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