kuros / random-jpa

Create random test data for JPA/Hibernate entities.
GNU General Public License v3.0
26 stars 4 forks source link

I can't generate the JPAContext #25

Closed jeremylima closed 6 years ago

jeremylima commented 6 years ago

Hello, I am using spring boot, when trying to create a jpaContext I get a exception

Code example:

@PersistenceContext
private EntityManager entityManager;

    @Test
    public void createAuthorization(){

        JPAContext jpaContext = JPAContextFactory.newInstance(Database.POSTGRES, entityManager)
                .generate();
   }

java.lang.NullPointerException at com.github.kuros.random.jpa.metamodel.MetaModelProviderImpl.getFieldsByTableName(MetaModelProviderImpl.java:51) at com.github.kuros.random.jpa.mapper.RelationCreator.(RelationCreator.java:45) at com.github.kuros.random.jpa.mapper.RelationCreator.from(RelationCreator.java:51) at com.github.kuros.random.jpa.JPAContextFactory.getCache(JPAContextFactory.java:117) at com.github.kuros.random.jpa.JPAContextFactory.generate(JPAContextFactory.java:105)

Can you help me please

MeatPopSci commented 6 years ago

I am running it the same issue on Hibernate MySQL 5

I can see in the com.github.kuros.random.jpa.util.Util line 179:

That method is unable to resolve the class which ultimately leads to your MetaModelProviderImpl not resolving your EntityTableMapping (near line 49).

Ping me for more details.

Cheers! On Fri, Jan 12, 2018 at 11:10 AM Jeremy Lima notifications@github.com wrote:

Hello, I am using spring boot, when trying to create a jpaContext I get a exception

Code example:

@PersistenceContext private EntityManager entityManager;

@Test
public void createAuthorization(){

    JPAContext jpaContext = JPAContextFactory.newInstance(Database.POSTGRES, entityManager)
            .generate();

}

java.lang.NullPointerException at com.github.kuros.random.jpa.metamodel.MetaModelProviderImpl.getFieldsByTableName(MetaModelProviderImpl.java:51) at com.github.kuros.random.jpa.mapper.RelationCreator.(RelationCreator.java:45) at com.github.kuros.random.jpa.mapper.RelationCreator.from(RelationCreator.java:51) at com.github.kuros.random.jpa.JPAContextFactory.getCache(JPAContextFactory.java:117) at com.github.kuros.random.jpa.JPAContextFactory.generate(JPAContextFactory.java:105)

Can you help me please

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kuros/random-jpa/issues/25, or mute the thread https://github.com/notifications/unsubscribe-auth/ABXZ3mviOG3Dp_ZKLhYyDwSUVZM04cPEks5tJ6wPgaJpZM4Rcrry .

MeatPopSci commented 6 years ago

This is Jonathan BTW! On Fri, Jan 12, 2018 at 4:18 PM Jonathan Raflowski jraflowski@gmail.com wrote:

I am running it the same issue on Hibernate MySQL 5

I can see in the com.github.kuros.random.jpa.util.Util line 179:

That method is unable to resolve the class which ultimately leads to your MetaModelProviderImpl not resolving your EntityTableMapping (near line 49).

Ping me for more details.

Cheers! On Fri, Jan 12, 2018 at 11:10 AM Jeremy Lima notifications@github.com wrote:

Hello, I am using spring boot, when trying to create a jpaContext I get a exception

Code example:

@PersistenceContext private EntityManager entityManager;

@Test
public void createAuthorization(){

    JPAContext jpaContext = JPAContextFactory.newInstance(Database.POSTGRES, entityManager)
            .generate();

}

java.lang.NullPointerException at com.github.kuros.random.jpa.metamodel.MetaModelProviderImpl.getFieldsByTableName(MetaModelProviderImpl.java:51) at com.github.kuros.random.jpa.mapper.RelationCreator.(RelationCreator.java:45) at com.github.kuros.random.jpa.mapper.RelationCreator.from(RelationCreator.java:51) at com.github.kuros.random.jpa.JPAContextFactory.getCache(JPAContextFactory.java:117) at com.github.kuros.random.jpa.JPAContextFactory.generate(JPAContextFactory.java:105)

Can you help me please

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/kuros/random-jpa/issues/25, or mute the thread https://github.com/notifications/unsubscribe-auth/ABXZ3mviOG3Dp_ZKLhYyDwSUVZM04cPEks5tJ6wPgaJpZM4Rcrry .

kuros commented 6 years ago

Please let know few details:

  1. Which is your entityprovider (Hibernate vs EclipseLink)
  2. What version of entity provider are you using. (Exact version)

This information will help me reproduce & fix issue.

kuros commented 6 years ago

Please try out Random-JPA v0.5.4.

I have fixed the issue, hibernate versions was not backward compatible hence provide failed to load entity details, also there was a piece of code which was swallowing the actual root cause, leading to a null pointer.

Do let me know if the issue is fixed, i will close the issue.

Thanks @MeatPopSci helping me fix the issue.

jeremylima commented 6 years ago

I keep having problems, the issue related with MetaModelProviderImpl was fixed, but I am getting the following error:

javax.persistence.PersistenceException: org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [table_name] during auto-discovery of a native-sql query

    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1692)
    at org.hibernate.jpa.spi.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1602)
    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:492)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:372)
    at com.sun.proxy.$Proxy171.getResultList(Unknown Source)
    at com.github.kuros.random.jpa.provider.base.AbstractRelationshipProvider.getForeignKeyRelations(AbstractRelationshipProvider.java:38)
    at com.github.kuros.random.jpa.mapper.RelationCreator.with(RelationCreator.java:55)
    at com.github.kuros.random.jpa.JPAContextFactory.getCache(JPAContextFactory.java:119)
    at com.github.kuros.random.jpa.JPAContextFactory.generate(JPAContextFactory.java:105)
    at com.osigu.clients.cases.CreateClient.createInsurer(CreateClient.java:32)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:84)
    at org.testng.internal.MethodInvocationHelper$1.runTestMethod(MethodInvocationHelper.java:200)
    at org.springframework.test.context.testng.AbstractTestNGSpringContextTests.run(AbstractTestNGSpringContextTests.java:175)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.testng.internal.MethodInvocationHelper.invokeHookable(MethodInvocationHelper.java:212)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:707)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:767)
    at org.testng.TestRunner.run(TestRunner.java:617)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:348)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:343)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:305)
    at org.testng.SuiteRunner.run(SuiteRunner.java:254)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1224)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1149)
    at org.testng.TestNG.run(TestNG.java:1057)
    at org.testng.IDEARemoteTestNG.run(IDEARemoteTestNG.java:72)
    at org.testng.RemoteTestNGStarter.main(RemoteTestNGStarter.java:123)
Caused by: org.hibernate.loader.custom.NonUniqueDiscoveredSqlAliasException: Encountered a duplicated sql alias [table_name] during auto-discovery of a native-sql query
    at org.hibernate.loader.custom.CustomLoader.validateAliases(CustomLoader.java:513)
    at org.hibernate.loader.custom.CustomLoader.autoDiscoverTypes(CustomLoader.java:490)
    at org.hibernate.loader.Loader.getResultSet(Loader.java:2125)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1900)
    at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1876)
    at org.hibernate.loader.Loader.doQuery(Loader.java:919)
    at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:336)
    at org.hibernate.loader.Loader.doList(Loader.java:2617)
    at org.hibernate.loader.Loader.doList(Loader.java:2600)
    at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2429)
    at org.hibernate.loader.Loader.list(Loader.java:2424)
    at org.hibernate.loader.custom.CustomLoader.list(CustomLoader.java:336)
    at org.hibernate.internal.SessionImpl.listCustomQuery(SessionImpl.java:1967)
    at org.hibernate.internal.AbstractSessionImpl.list(AbstractSessionImpl.java:322)
    at org.hibernate.internal.SQLQueryImpl.list(SQLQueryImpl.java:125)
    at org.hibernate.jpa.internal.QueryImpl.list(QueryImpl.java:606)
    at org.hibernate.jpa.internal.QueryImpl.getResultList(QueryImpl.java:483)

I am using hibernate 5.0.12.Final. I have only one table in my model

These are the DLL's for the database objects:

CREATE SEQUENCE public.clients_id_seq
INCREMENT BY 1
MINVALUE 1
MAXVALUE 9223372036854775807
START 1;

CREATE TABLE public.clients (
    id int4 NOT NULL DEFAULT nextval('clients_id_seq'::regclass),
    "name" varchar(100) NOT NULL,
    created_at timestamptz NOT NULL DEFAULT now(),
    updated_at timestamptz NULL DEFAULT now(),
    PRIMARY KEY (id)
)
WITH (
    OIDS=FALSE
) ;
CREATE UNIQUE INDEX clients_name_idx1 ON clients USING btree (upper((name)::text)) ;

Let me know if you want more details.

Thanks

kuros commented 6 years ago

can you provide me Progress version.

Also, Do you get any errors while running the below queries:-

SELECT tc.table_name, kcu.column_name, ccu.table_name, ccu.column_name FROM information_schema.table_constraints AS tc JOIN information_schema.key_column_usage AS kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage AS ccu ON ccu.constraint_name = tc.constraint_name WHERE constraint_type = 'FOREIGN KEY';

jeremylima commented 6 years ago

The query is executed but it's not returning anything. The postgres connector version is: 9.1-901-1.jdbc4. Server version: PostgreSQL 9.4.5 on x86_64-unknown-linux-gnu, compiled by gcc (Debian 4.9.2-10) 4.9.2, 64-bit

Also I changed the provider to mysql and all is working fine, the issue is with postgres.

kuros commented 6 years ago

Fixed the issue with v0.5.5

jeremylima commented 6 years ago

Working fine,

Thanks