[Hibernate-JIRA] Created: (HHH-6638) One to One Mapping of Composite Keys
by Srikanth Rajkumar (JIRA)
One to One Mapping of Composite Keys
------------------------------------
Key: HHH-6638
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6638
Project: Hibernate Core
Issue Type: Bug
Components: annotations, core, entity-manager, query-hql
Affects Versions: 3.5.5
Environment: Below are the list of jars included in the classpath.
hibernate-commons-annotations-3.2.0.Final.jar
hibernate-annotations-3.5.5-Final.jar
hibernate-core-3.5.5-Final.jar
hibernate-entitymanager-3.5.5-Final.jar
hibernate-jpa-2.0-api-1.0.0.Final.jar
log4j-1.2.14.jar
dom4j-1.6.1.jar
slf4j-api-1.5.6.jar
slf4j-log4j12-1.5.6.jar
javaassist-3.9.0.GA.jar
derbyclient.jar
commons-collections-3.2.1.jar
jta-1.1.jar
antlr-2.7.6.jar
The database used is derby. Below is the table create scripts
CREATE TABLE VYA6CPP (
A6VN9K VARCHAR(9),
A6VN8K VARCHAR(8),
A6J2CD VARCHAR(20),
PRIMARY KEY(A6VN9K, A6VN8K)
)
CREATE TABLE MAMAM1 (
M1VIN1 VARCHAR(9),
M1VIN2 VARCHAR(8),
M1SHPR VARCHAR(4),
PRIMARY KEY(M1VIN1, M1VIN2),
FOREIGN KEY(M1VIN1, M1VIN2) REFERENCES VYA6CPP(A6VN9K, A6VN8K)
)
Reporter: Srikanth Rajkumar
Attachments: src.zip
When the attached source is executed, i am getting the below error. Hibernate is not able to map composite keys if the keys names are different. For more information, visit this topic https://forum.hibernate.org/viewtopic.php?f=1&t=1012396
2011-09-07 02:36:21,080 [INFO] [org.hibernate.cfg.annotations.Version] - <Hibernate Annotations 3.5.5-Final>
2011-09-07 02:36:21,111 [INFO] [org.hibernate.cfg.Environment] - <Hibernate 3.5.5-Final>
2011-09-07 02:36:21,111 [INFO] [org.hibernate.cfg.Environment] - <hibernate.properties not found>
2011-09-07 02:36:21,127 [INFO] [org.hibernate.cfg.Environment] - <Bytecode provider name : javassist>
2011-09-07 02:36:21,142 [INFO] [org.hibernate.cfg.Environment] - <using JDK 1.4 java.sql.Timestamp handling>
2011-09-07 02:36:21,486 [INFO] [org.hibernate.annotations.common.Version] - <Hibernate Commons Annotations 3.2.0.Final>
2011-09-07 02:36:21,502 [INFO] [org.hibernate.ejb.Version] - <Hibernate EntityManager 3.5.5-Final>
2011-09-07 02:36:21,939 [INFO] [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.hibernate.examples.entities.Mamam1>
2011-09-07 02:36:22,002 [INFO] [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.hibernate.examples.entities.Mamam1 on table MAMAM1>
2011-09-07 02:36:22,096 [INFO] [org.hibernate.cfg.AnnotationBinder] - <Binding entity from annotated class: com.hibernate.examples.entities.Vya6cpp>
2011-09-07 02:36:22,096 [INFO] [org.hibernate.cfg.annotations.EntityBinder] - <Bind entity com.hibernate.examples.entities.Vya6cpp on table VYA6CPP>
2011-09-07 02:36:22,111 [INFO] [org.hibernate.cfg.AnnotationConfiguration] - <Hibernate Validator not found: ignoring>
2011-09-07 02:36:22,142 [INFO] [org.hibernate.cfg.search.HibernateSearchEventListenerRegister] - <Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.>
2011-09-07 02:36:22,299 [WARN] [org.hibernate.mapping.RootClass] - <composite-id class does not override equals(): com.hibernate.examples.entities.Vya6cppPK>
2011-09-07 02:36:22,299 [WARN] [org.hibernate.mapping.RootClass] - <composite-id class does not override hashCode(): com.hibernate.examples.entities.Vya6cppPK>
2011-09-07 02:36:22,314 [WARN] [org.hibernate.mapping.RootClass] - <composite-id class does not override equals(): com.hibernate.examples.entities.Mamam1PK>
2011-09-07 02:36:22,314 [WARN] [org.hibernate.mapping.RootClass] - <composite-id class does not override hashCode(): com.hibernate.examples.entities.Mamam1PK>
2011-09-07 02:36:22,314 [INFO] [org.hibernate.connection.DriverManagerConnectionProvider] - <Using Hibernate built-in connection pool (not for production use!)>
2011-09-07 02:36:22,314 [INFO] [org.hibernate.connection.DriverManagerConnectionProvider] - <Hibernate connection pool size: 20>
2011-09-07 02:36:22,314 [INFO] [org.hibernate.connection.DriverManagerConnectionProvider] - <autocommit mode: true>
2011-09-07 02:36:22,346 [INFO] [org.hibernate.connection.DriverManagerConnectionProvider] - <using driver: org.apache.derby.jdbc.ClientDriver at URL: jdbc:derby://localhost:1527/sample;>
2011-09-07 02:36:22,346 [INFO] [org.hibernate.connection.DriverManagerConnectionProvider] - <connection properties: {user=sample, password=****, autocommit=true, release_mode=auto}>
2011-09-07 02:36:22,783 [INFO] [org.hibernate.cfg.SettingsFactory] - <RDBMS: Apache Derby, version: 10.3.1.4 - (561794)>
2011-09-07 02:36:22,783 [INFO] [org.hibernate.cfg.SettingsFactory] - <JDBC driver: Apache Derby Network Client JDBC Driver, version: 10.3.1.4 - (561794)>
2011-09-07 02:36:22,846 [INFO] [org.hibernate.dialect.Dialect] - <Using dialect: org.hibernate.dialect.DerbyDialect>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.transaction.TransactionFactoryFactory] - <Transaction strategy: org.hibernate.transaction.JDBCTransactionFactory>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.transaction.TransactionManagerLookupFactory] - <No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Automatic flush during beforeCompletion(): disabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Automatic session close at end of transaction: disabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Scrollable result sets: enabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <JDBC3 getGeneratedKeys(): disabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Connection release mode: auto>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Default batch fetch size: 1>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Generate SQL with comments: disabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Order SQL updates by primary key: disabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Order SQL inserts for batching: disabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.hql.ast.ASTQueryTranslatorFactory] - <Using ASTQueryTranslatorFactory>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Query language substitutions: {}>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <JPA-QL strict compliance: enabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Second-level cache: enabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Query cache: disabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Cache region factory : org.hibernate.cache.impl.NoCachingRegionFactory>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Optimize cache for minimal puts: disabled>
2011-09-07 02:36:23,018 [INFO] [org.hibernate.cfg.SettingsFactory] - <Structured second-level cache entries: disabled>
2011-09-07 02:36:23,033 [INFO] [org.hibernate.cfg.SettingsFactory] - <Echoing all SQL to stdout>
2011-09-07 02:36:23,033 [INFO] [org.hibernate.cfg.SettingsFactory] - <Statistics: disabled>
2011-09-07 02:36:23,033 [INFO] [org.hibernate.cfg.SettingsFactory] - <Deleted entity synthetic identifier rollback: disabled>
2011-09-07 02:36:23,033 [INFO] [org.hibernate.cfg.SettingsFactory] - <Default entity-mode: pojo>
2011-09-07 02:36:23,033 [INFO] [org.hibernate.cfg.SettingsFactory] - <Named query checking : enabled>
2011-09-07 02:36:23,033 [INFO] [org.hibernate.cfg.SettingsFactory] - <Check Nullability in Core (should be disabled when Bean Validation is on): enabled>
2011-09-07 02:36:23,111 [INFO] [org.hibernate.impl.SessionFactoryImpl] - <building session factory>
2011-09-07 02:36:23,346 [INFO] [org.hibernate.impl.SessionFactoryObjectFactory] - <Not binding factory to JNDI, no JNDI name configured>
Hibernate: select mamam1x0_.M1VIN1 as M1_0_, mamam1x0_.M1VIN2 as M2_0_, mamam1x0_.M1SHPR as M3_0_ from MAMAM1 mamam1x0_
2011-09-07 02:36:23,768 [ERROR] [com.hibernate.examples.main.Main] - <Exception>
java.lang.IllegalArgumentException: org.hibernate.TypeMismatchException: Provided id of the wrong type for class com.hibernate.examples.entities.Vya6cpp. Expected: class com.hibernate.examples.entities.Vya6cppPK, got class com.hibernate.examples.entities.Mamam1PK
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:247)
at com.hibernate.examples.main.Main.method1(Main.java:44)
at com.hibernate.examples.testcase.MappingTestCase.testMain(MappingTestCase.java:26)
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.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:73)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:46)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:180)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:41)
at org.junit.runners.ParentRunner$1.evaluate(ParentRunner.java:173)
at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
at org.junit.runners.ParentRunner.run(ParentRunner.java:220)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.hibernate.TypeMismatchException: Provided id of the wrong type for class com.hibernate.examples.entities.Vya6cpp. Expected: class com.hibernate.examples.entities.Vya6cppPK, got class com.hibernate.examples.entities.Mamam1PK
at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:135)
at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:1080)
at org.hibernate.impl.SessionImpl.internalLoad(SessionImpl.java:1028)
at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:623)
at org.hibernate.type.EntityType.resolve(EntityType.java:431)
at org.hibernate.engine.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:140)
at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:898)
at org.hibernate.loader.Loader.doQuery(Loader.java:773)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270)
at org.hibernate.loader.Loader.doList(Loader.java:2449)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2192)
at org.hibernate.loader.Loader.list(Loader.java:2187)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:241)
... 26 more
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 3 months
[Hibernate-JIRA] Created: (HHH-2955) Unnecessary version updates in two cases.
by Sławomir Wojtasiak (JIRA)
Unnecessary version updates in two cases.
-----------------------------------------
Key: HHH-2955
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2955
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.5
Environment: JDK 5.0
Reporter: Sławomir Wojtasiak
Attachments: HibernateTest.zip
I found two situations where hibernate generates unnecessary version updates. Let's illustrate it with a simple example:
Session session = SessionFactory.getSession();
Transaction transaction = session.getTransaction();
transaction.begin();
Article a = new Article();
a.setName( "atricle" );
*********************************************
*** Quantity is the owner of the relation ***
*********************************************
Quantity q = new Quantity();
q.setName( "quantity" );
q.setArticle( a );
a.getQuantities().add( q );
session.persist( a );
session.flush();
***** Hibernate generates following SQLs *****
Hibernate: select nextval ('hibernate_sequence')
Hibernate: select nextval ('hibernate_sequence')
Hibernate: insert into Article (name, version, id) values (?, ?, ?)
Hibernate: insert into Quantity (article_id, name, version, id) values (?, ?, ?, ?)
**********************************************
a.getQuantities().clear();
session.flush();
*** Hibernate generates following SQLs ***
Hibernate: update Article set name=?, version=? where id=? and version=?
This update of version field is performed because collection of quantities is marked as dirty, but Article entity is not relation owner so nothing change in database after this clear. Should it works like this? It looks like a bug because database remain unchanged so version changing is unnecessary in my opinion.
******************************************
session.clear();
**** SECOND PROBLEM ***
Now I generate true copy of persisted objects.
Notice that I use HashSet instead of PersistSet which was set during persist operation. This operation is similar to merging objects prepared by SOAP, during communication with remote client for example.
***********************
Article a1 = new Article();
a1.setId( a.getId() );
a1.setName( a.getName() );
a1.setVersion( a.getVersion() );
Quantity q1 = new Quantity();
q1.setArticle( a1 );
q1.setName( q.getName() );
q1.setVersion( q.getVersion() );
q1.setId( q.getId() );
a1.getQuantities().add( q1 );
a1 = (Article)session.merge( a1 );
session.flush();
***** This operation generates following SQLs *****
Hibernate: select article0_.id as id0_1_, article0_.name as name0_1_, article0_.version as version0_1_, quantities1_.article_id as article4_3_, quantities1_.id as id3_, quantities1_.id as id1_0_, quantities1_.article_id as article4_1_0_, quantities1_.name as name1_0_, quantities1_.version as version1_0_ from Article article0_ left outer join Quantity quantities1_ on article0_.id=quantities1_.article_id where article0_.id=?
Hibernate: update Article set name=?, version=? where id=? and version=?
It looks like problem is located in replaceElements() method of CollectgionType class (or somewhere near it). Maybe I'm wrong but this collection was checked for changes during merge operation (See this select above.) so why it remains dirty if it contains the same data as database?. I checked this issue on other JPA implementations (OpenJPA for example) and version is not incremented after similar merge operation.
*****************************************************
transaction.rollback();
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 3 months
[Hibernate-JIRA] Created: (HHH-6633) SchemaExport tool swallows interesting exceptions whilst reporting on irrelevant exceptions
by Ben Hood (JIRA)
SchemaExport tool swallows interesting exceptions whilst reporting on irrelevant exceptions
-------------------------------------------------------------------------------------------
Key: HHH-6633
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-6633
Project: Hibernate Core
Issue Type: Bug
Affects Versions: 3.6.5
Environment: 3.6.5 Oracle 11g
Reporter: Ben Hood
I don't think the API of the SchemaExport tool is quite right. When using it to create a fresh DDL, the SQL errors that result from the (irrelevant) DROP statements are collected in a list member of the SchemaExport instance. These errors are skipped over, because they usually occur when you have a fresh database, but their occurrence is recorded. This is uncool because when you set the haltOnError flag, as soon as it hits an error that you do actually care about, e.g. can't create a table for some reason, a JDBCException is raised. However, this exception is caught by higher level code, and hence the invoker does not get notified of that error. To make matters worse, you can't then introspect the collected errors, it is just full of the SQLExceptions generated by the DROP statements, but there is nothing to demarcate them as such. You are left with a situation where you don't really know if an error has occurred that you should care about.
If you would like a patch to correct this behavior, I would be happy to supply one.
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira
13 years, 3 months