LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   why is hibernate (or someone else) changing my class name? (http://www.linuxquestions.org/questions/programming-9/why-is-hibernate-or-someone-else-changing-my-class-name-935046/)

eantoranz 03-18-2012 03:25 AM

why is hibernate (or someone else) changing my class name?
 
Hi!

I'm working on a java application that connects to one PG db that uses uuid. I tried with ebean as a ORM provider but failed miserably on it so now I want to see if hibernate can do the job for me. I'm trying with a very simple standone application with one entity so that I can make sure that hibernate will take care of the uuid stuff correctly.

So, after fighting for a while to try to make the standalone application run I think I'm almost there. On the startup it even complains if the META-INF/persistence.xml file is not in the classpath. But now, when I run the application I see that for whatever reason, someone is trying to load the class I asked to load but with one "bin" prepended to it:

Code:

$ java -cp ./:/home/antoranz/Downloads/java/hibernate-release-4.1.1.Final/lib/required/hibernate-core-4.1.1.Final.jar:/home/antoranz/Downloads/java/hibernate-release-4.1.1.Final/lib/jpa/hibernate-entitymanager-4.1.1.Final.jar:/home/antoranz/Downloads/java/hibernate-release-4.1.1.Final/lib/required/hibernate-jpa-2.0-api-1.0.1.Final.jar:/home/antoranz/Downloads/java/hibernate-release-4.1.1.Final/lib/required/jboss-logging-3.1.0.GA.jar:/home/antoranz/Downloads/java/hibernate-release-4.1.1.Final/lib/required/jboss-transaction-api_1.1_spec-1.0.0.Final.jar:/home/antoranz/Downloads/java/hibernate-release-4.1.1.Final/lib/required/dom4j-1.6.1.jar:/home/antoranz/Downloads/java/hibernate-release-4.1.1.Final/lib/required/hibernate-commons-annotations-4.0.1.Final.jar:/home/antoranz/Downloads/java/hibernate-release-4.1.1.Final/lib/required/javassist-3.15.0-GA.jar:../ test.Entidad1
18/03/2012 02:17:38 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
18/03/2012 02:17:38 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.1}
18/03/2012 02:17:38 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
18/03/2012 02:17:38 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
Exception in thread "main" java.lang.NoClassDefFoundError: bin/test/Entidad1 (wrong name: test/Entidad1)
        at java.lang.ClassLoader.defineClass1(Native Method)
        at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
        at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
        at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
        at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
        at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
        at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
        at java.security.AccessController.doPrivileged(Native Method)
        at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:169)
        at org.hibernate.internal.util.ReflectHelper.classForName(ReflectHelper.java:192)
        at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:134)
        at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:484)
        at org.hibernate.ejb.Ejb3Configuration.addMetadataFromScan(Ejb3Configuration.java:474)
        at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:360)
        at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:63)
        at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:47)
        at test.Entidad1.main(Entidad1.java:43)

See? I asked for test.Entidad1 and someone asked to load bin.test.Entidad1. Why is that? Thanks in advance.

eantoranz 03-18-2012 03:31 AM

Oh.... I think I have a theory. It's because I'm providing both ./ and ../ in the classpath. ./ is inside bin, but then I have ../ so that java can find META-INF that's not in bin. So when org.hibernate.ejb.packaging.NativeScanner.getClassesInJar check's the path, of course, one of the paths (or packages, in java lingo) is broken. I'll try using a single dir for everything. Hold your breath.

eantoranz 03-18-2012 03:35 AM

That solved it. I ln-sed META-INF into bin and it worked. However hibernate crashes on the same problem:

Code:

18/03/2012 02:33:17 AM org.hibernate.annotations.common.Version <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {4.0.1.Final}
18/03/2012 02:33:17 AM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {4.1.1}
18/03/2012 02:33:17 AM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
18/03/2012 02:33:17 AM org.hibernate.cfg.Environment buildBytecodeProvider
INFO: HHH000021: Bytecode provider name : javassist
18/03/2012 02:33:19 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000402: Using Hibernate built-in connection pool (not for production use!)
18/03/2012 02:33:19 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000115: Hibernate connection pool size: 20
18/03/2012 02:33:19 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000006: Autocommit mode: true
18/03/2012 02:33:19 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000401: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5433/uuid]
18/03/2012 02:33:19 AM org.hibernate.service.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
INFO: HHH000046: Connection properties: {user=postgres, password=****, autocommit=true, release_mode=auto}
18/03/2012 02:33:20 AM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL81Dialect
18/03/2012 02:33:20 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
INFO: HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
18/03/2012 02:33:20 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
INFO: HHH000268: Transaction strategy: org.hibernate.engine.transaction.internal.jdbc.JdbcTransactionFactory
18/03/2012 02:33:20 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
INFO: HHH000397: Using ASTQueryTranslatorFactory
18/03/2012 02:33:22 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42883
18/03/2012 02:33:22 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERROR: operator does not exist: uuid = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 113
18/03/2012 02:33:22 AM org.hibernate.event.internal.DefaultLoadEventListener onLoad
INFO: HHH000327: Error performing load command : org.hibernate.exception.SQLGrammarException: ERROR: operator does not exist: uuid = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 113
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: ERROR: operator does not exist: uuid = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 113
        at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1360)
        at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:817)
        at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:771)
        at test.Entidad1.main(Entidad1.java:45)
Caused by: org.hibernate.exception.SQLGrammarException: ERROR: operator does not exist: uuid = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 113
        at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:122)
        at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)
        at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110)
        at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:129)
        at org.hibernate.engine.jdbc.internal.proxy.AbstractProxyHandler.invoke(AbstractProxyHandler.java:81)
        at $Proxy7.executeQuery(Unknown Source)
        at org.hibernate.loader.Loader.getResultSet(Loader.java:1962)
        at org.hibernate.loader.Loader.doQuery(Loader.java:829)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:289)
        at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
        at org.hibernate.loader.Loader.loadEntity(Loader.java:2042)
        at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)
        at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)
        at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3710)
        at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:440)
        at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:421)
        at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:205)
        at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:252)
        at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:149)
        at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:992)
        at org.hibernate.internal.SessionImpl.access$1900(SessionImpl.java:170)
        at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2336)
        at org.hibernate.internal.SessionImpl.get(SessionImpl.java:888)
        at org.hibernate.ejb.AbstractEntityManagerImpl.find(AbstractEntityManagerImpl.java:796)
        ... 2 more
Caused by: org.postgresql.util.PSQLException: ERROR: operator does not exist: uuid = bytea
  Hint: No operator matches the given name and argument type(s). You might need to add explicit type casts.
  Position: 113
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2077)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1810)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:257)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:498)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:386)
        at org.postgresql.jdbc2.AbstractJdbc2Statement.executeQuery(AbstractJdbc2Statement.java:271)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        at org.hibernate.engine.jdbc.internal.proxy.AbstractStatementProxyHandler.continueInvocation(AbstractStatementProxyHandler.java:122)
        ... 22 more

Looks like I'll have to sit down to hack some ORM to get this done.


All times are GMT -5. The time now is 10:37 AM.