[Hibernate-JIRA] Closed: (HBX-581) hibernate-reverse-engineering IDENTITY generator doesn't result in correct annotation
by Max Rydahl Andersen (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HBX-581?page=co... ]
Max Rydahl Andersen closed HBX-581.
-----------------------------------
> hibernate-reverse-engineering IDENTITY generator doesn't result in correct annotation
> -------------------------------------------------------------------------------------
>
> Key: HBX-581
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-581
> Project: Hibernate Tools
> Issue Type: Bug
> Components: reverse-engineer
> Affects Versions: 3.1beta4
> Reporter: Matt Read
>
> My hibernate.reveng.xml contains the following:
> <table catalog="Swan" schema="InsuranceLedger" name="jouJournal">
> <primary-key>
> <generator class="IDENTITY"></generator>
> </primary-key>
> </table>
> This results in the following annotations on my @Id field when generating annotated Java:
> @GenericGenerator(name="generator", strategy="IDENTITY", parameters = { } )
> @Id @GeneratedValue(generator="generator")
> @Column(name="jouSID", unique=true, nullable=false, insertable=true, updatable=true)
> public Long getsID() {
> return this.sID;
> }
> Which results in the following error at runtime:
> org.hibernate.MappingException: could not instantiate id generator
> at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:97)
> at org.hibernate.mapping.SimpleValue.createIdentifierGenerator(SimpleValue.java:152)
> at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:181)
> at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
> at com.catlin.architecture.dao.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:80)
> at com.catlin.insuranceledger.JournalTest.setUp(JournalTest.java:38)
> at junit.framework.TestCase.runBare(TestCase.java:125)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
> Caused by: org.hibernate.MappingException: could not interpret id generator strategy: IDENTITY
> at org.hibernate.id.IdentifierGeneratorFactory.getIdentifierGeneratorClass(IdentifierGeneratorFactory.java:108)
> at org.hibernate.id.IdentifierGeneratorFactory.create(IdentifierGeneratorFactory.java:91)
> ... 15 more
> Replacing the generated annotation with the following works fine:
> @Id
> @GeneratedValue(strategy=GenerationType.IDENTITY)
> @Column(name="jouSID", unique=true, nullable=false, insertable=true, updatable=true)
> public Long getsID() {
> return this.sID;
> }
--
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
17 years, 8 months
[Hibernate-JIRA] Created: (HBX-934) Mismatched order of composite keys in joins
by Anthony Patricio (JIRA)
Mismatched order of composite keys in joins
-------------------------------------------
Key: HBX-934
URL: http://opensource.atlassian.com/projects/hibernate/browse/HBX-934
Project: Hibernate Tools
Issue Type: Bug
Components: reverse-engineer
Affects Versions: 3.2beta9
Reporter: Anthony Patricio
http://opensource.atlassian.com/projects/hibernate/browse/ANN-571
According to the JPA specification (p. 169) if there are multiple @JoinColumn annotations specified within an @JoinColumns annotation then both name and referencedColumnName attributes must be used:
"If there is more than one join column, a JoinColumn annotation must be specified for each join column
using the JoinColumns annotation. Both the name and the referencedColumnName elements
must be specified in each such JoinColumn annotation."
Right now, if I leave off the referencedColumnName everything appears to work but I get some random SQL. For instance, say I have two tables TABLE1 and TABLE2 and they are joined on the columns ID and TYPE, sometimes I get the right join condition:
TABLE1.ID = TABLE2.ID AND TABLE1.TYPE = TABLE2.TYPE
but sometimes I get:
TABLE1.ID = TABLE2.TYPE AND TABLE1.TYPE = TABLE2.ID
Adding the referencedColumnName makes that issue go away.
Emmanuel thinks the easiest way to solve this is to explicit the column names, as the spec recommend.
--
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
17 years, 8 months
[Hibernate-JIRA] Created: (HHH-2581) Property access and type utilization conflict between runtime and code generation.
by ssarver (JIRA)
Property access and type utilization conflict between runtime and code generation.
-----------------------------------------------------------------------------------
Key: HHH-2581
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2581
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.3
Environment: Fedora Core 6
Reporter: ssarver
Priority: Minor
Attachments: jira.zip
########################################################
#
# README
#
########################################################
INSTRUCTIONS:
0) Edit hibernate.cfg.xml
1) Run user_ty.ddl
2) Execute: ant test
>>>If code generation is performed with the type attribute
set to the derived UserType
<property name="user" type="test.UserUserType">
<meta attribute="use-in-tostring">true</meta>
<column name="userObject" sql-type="USER_TY"/>
</property>
then hbm2java creates a Person with the derived UserType:
package test;
/**
* Person generated by hbm2java
*/
public class Person implements java.io.Serializable {
private long id;
private String name;
private long age;
private UserUserType user;
public Person() {
}
public Person(String name, long age) {
this.name = name;
this.age = age;
}
public Person(String name, long age, UserUserType user) {
this.name = name;
this.age = age;
this.user = user;
}
...
>>>If code generation is performed with the access attribute set to
the derived UserType and the type set to User:
<property name="user" access="test.UserUserType" type="test.User">
<meta attribute="use-in-tostring">true</meta>
<column name="userObject" sql-type="USER_TY"/>
</property>
then hbm2java creates a Person with the desired User type:
package test;
/**
* Person generated by hbm2java
*/
public class Person implements java.io.Serializable {
private long id;
private String name;
private long age;
private User user;
public Person() {
}
public Person(String name, long age) {
this.name = name;
this.age = age;
}
public Person(String name, long age, User user) {
this.name = name;
this.age = age;
this.user = user;
}
...
However, using the following mapping at runtime:
<property name="user" access="test.UserUserType" type="test.User">
<meta attribute="use-in-tostring">true</meta>
<column name="userObject" sql-type="USER_TY"/>
</property>
produces the error:
[java] Caused by: java.lang.ExceptionInInitializerError
[java] at persistence.HibernateUtil.<clinit>(Unknown Source)
[java] at test.TestPerson.testCreatePerson(Unknown Source)
[java] at test.TestPerson.main(Unknown Source)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
[java] ... 20 more
[java] Caused by: org.hibernate.MappingException: Could not determine type for: test.User, for columns: [org.hibernate.
mapping.Column(userObject)]
Complete run:
ssarver beta/home/ssarver/jira> ant test
Buildfile: build.xml
hbm:
[hibernate-tool] Executing Hibernate Tool with a Standard Configuration
[hibernate-tool] 1. task: hbm2java (Generates a set of .java files)
[hibernate-tool] 08:39:29,040 INFO Environment:509 - Hibernate 3.2.3
[hibernate-tool] 08:39:29,076 INFO Environment:542 - hibernate.properties not found
[hibernate-tool] 08:39:29,083 INFO Environment:676 - Bytecode provider name : cglib
[hibernate-tool] 08:39:29,114 INFO Environment:593 - using JDK 1.4 java.sql.Timestamp handling
[hibernate-tool] 08:39:29,381 INFO Configuration:1460 - configuring from file: hibernate.cfg.xml
[hibernate-tool] 08:39:29,611 INFO Configuration:1541 - Configured SessionFactory: null
[hibernate-tool] 08:39:29,618 INFO Configuration:299 - Reading mappings from file: /home/ssarver/jira/src/test/Person.hbm.x
ml
[hibernate-tool] 08:39:29,942 INFO HbmBinder:300 - Mapping class: test.Person -> person
[hibernate-tool] 08:39:30,393 INFO Version:15 - Hibernate Tools 3.2.0.b9
[hibernate-tool] 2. task: hbm2dao (Generates a set of DAOs)
[hibernate-tool] 3. task: hbm2ddl (Generates database schema)
[hibernate-tool] 08:39:32,450 INFO Dialect:152 - Using dialect: org.hibernate.dialect.Oracle9Dialect
[hibernate-tool] 08:39:32,597 INFO SchemaExport:154 - Running hbm2ddl schema export
[hibernate-tool] 08:39:32,607 INFO SchemaExport:174 - writing generated schema to file: /home/ssarver/jira/target/src/test.
ddl
[hibernate-tool] 08:39:32,609 INFO SchemaExport:179 - exporting generated schema to database
[hibernate-tool] 08:39:32,650 INFO DriverManagerConnectionProvider:41 - Using Hibernate built-in connection pool (not for p
roduction use!)
[hibernate-tool] 08:39:32,656 INFO DriverManagerConnectionProvider:42 - Hibernate connection pool size: 20
[hibernate-tool] 08:39:32,657 INFO DriverManagerConnectionProvider:45 - autocommit mode: false
[hibernate-tool] 08:39:32,708 INFO DriverManagerConnectionProvider:80 - using driver: oracle.jdbc.driver.OracleDriver at UR
L: jdbc:oracle:thin:@oracrcdbsdev01.sd.lpl.com:1526:lpldev
[hibernate-tool] 08:39:32,710 INFO DriverManagerConnectionProvider:86 - connection properties: {user=ops$ssarver, password=
****}
[hibernate-tool]
[hibernate-tool] drop function SELECT_PERSON_BY_NAME;
[hibernate-tool]
[hibernate-tool] drop table person cascade constraints;
[hibernate-tool]
[hibernate-tool] drop sequence hibernate_sequence;
[hibernate-tool]
[hibernate-tool] create table person (
[hibernate-tool] id number(19,0) not null,
[hibernate-tool] name varchar2(255 char) not null,
[hibernate-tool] age number(19,0) not null,
[hibernate-tool] userObject USER_TY,
[hibernate-tool] primary key (id)
[hibernate-tool] );
[hibernate-tool]
[hibernate-tool] create sequence hibernate_sequence;
[hibernate-tool]
[hibernate-tool] CREATE OR REPLACE FUNCTION SELECT_PERSON_BY_NAME(p_name varchar) RETURN SYS_REFCURSOR IS st_cursor SYS_
REFCURSOR; BEGIN OPEN st_cursor FOR SELECT * from person WHERE name LIKE '%' || p_name || '%'; RETURN st_cursor; END;;
[hibernate-tool] 08:39:34,224 INFO SchemaExport:196 - schema export complete
[hibernate-tool] 08:39:34,229 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:oracle:thin:@ora
crcdbsdev01.sd.lpl.com:1526:lpldev
[hibernate-tool] 4. task: hbm2cfgxml (Generates hibernate.cfg.xml)
copyhbm:
[mkdir] Created dir: /home/ssarver/jira/target/classes
[copy] Copying 1 file to /home/ssarver/jira/target/classes
build:
[javac] Compiling 6 source files to /home/ssarver/jira/target/classes
[javac] /home/ssarver/jira/target/src/test/Person.java
[javac] /home/ssarver/jira/target/src/test/PersonHome.java
[javac] /home/ssarver/jira/src/persistence/HibernateUtil.java
[javac] /home/ssarver/jira/src/test/TestPerson.java
[javac] /home/ssarver/jira/src/test/User.java
[javac] /home/ssarver/jira/src/test/UserUserType.java
08:39:35,740 INFO DriverManagerConnectionProvider:147 - cleaning up connection pool: jdbc:oracle:thin:@oracrcdbsdev01.sd.lp
l.com:1526:lpldev
jar:
[jar] Building jar: /home/ssarver/jira/target/test.jar
test:
[java] 08:39:37,901 INFO Environment:509 - Hibernate 3.2.3
[java] 08:39:37,960 INFO Environment:542 - hibernate.properties not found
[java] 08:39:37,967 INFO Environment:676 - Bytecode provider name : cglib
[java] 08:39:38,051 INFO Environment:593 - using JDK 1.4 java.sql.Timestamp handling
[java] 08:39:38,362 INFO Configuration:1426 - configuring from resource: /hibernate.cfg.xml
[java] 08:39:38,366 INFO Configuration:1403 - Configuration resource: /hibernate.cfg.xml
[java] 08:39:39,227 INFO Configuration:553 - Reading mappings from resource : test/Person.hbm.xml
[java] 08:39:39,594 INFO HbmBinder:300 - Mapping class: test.Person -> person
[java] 08:39:39,731 INFO Configuration:1541 - Configured SessionFactory: null
[java] java.lang.ExceptionInInitializerError
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:194)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:747)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:201)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:104)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[java] at org.apache.tools.ant.Task.perform(Task.java:348)
[java] at org.apache.tools.ant.Target.execute(Target.java:357)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:698)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:199)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
[java] Caused by: java.lang.ExceptionInInitializerError
[java] at persistence.HibernateUtil.<clinit>(Unknown Source)
[java] at test.TestPerson.testCreatePerson(Unknown Source)
[java] at test.TestPerson.main(Unknown Source)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
[java] ... 20 more
[java] Caused by: org.hibernate.MappingException: Could not determine type for: test.User, for columns: [org.hibernate.
mapping.Column(userObject)]
[java] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
[java] at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
[java] at org.hibernate.mapping.Property.isValid(Property.java:185)
[java] at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
[java] at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
[java] at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
[java] at persistence.HibernateUtil.<clinit>(Unknown Source)
[java] ... 28 more
[java] --- Nested Exception ---
[java] java.lang.ExceptionInInitializerError
[java] at persistence.HibernateUtil.<clinit>(Unknown Source)
[java] at test.TestPerson.testCreatePerson(Unknown Source)
[java] at test.TestPerson.main(Unknown Source)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:217)
[java] at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:152)
[java] at org.apache.tools.ant.taskdefs.Java.run(Java.java:747)
[java] at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:201)
[java] at org.apache.tools.ant.taskdefs.Java.execute(Java.java:104)
[java] at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:288)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[java] at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
[java] at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
[java] at java.lang.reflect.Method.invoke(Method.java:585)
[java] at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:105)
[java] at org.apache.tools.ant.Task.perform(Task.java:348)
[java] at org.apache.tools.ant.Target.execute(Target.java:357)
[java] at org.apache.tools.ant.Target.performTasks(Target.java:385)
[java] at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1329)
[java] at org.apache.tools.ant.Project.executeTarget(Project.java:1298)
[java] at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
[java] at org.apache.tools.ant.Project.executeTargets(Project.java:1181)
[java] at org.apache.tools.ant.Main.runBuild(Main.java:698)
[java] at org.apache.tools.ant.Main.startAnt(Main.java:199)
[java] at org.apache.tools.ant.launch.Launcher.run(Launcher.java:257)
[java] at org.apache.tools.ant.launch.Launcher.main(Launcher.java:104)
[java] Caused by: org.hibernate.MappingException: Could not determine type for: test.User, for columns: [org.hibernate.
mapping.Column(userObject)]
[java] at org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:266)
[java] at org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:253)
[java] at org.hibernate.mapping.Property.isValid(Property.java:185)
[java] at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:440)
[java] at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
[java] at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
[java] at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
[java] at persistence.HibernateUtil.<clinit>(Unknown Source)
[java] ... 28 more
BUILD SUCCESSFUL
Total time: 13 seconds
ssarver beta/home/ssarver/jira>
>>>Work Around:
Change the name of
hbm/test/Person.hbm.xml.hide
to hbm/test/Person.hbm.xml
and this file to ensure that this mapping definition is
is included in test.jar and not src/test/Person.hbm.xml
This way, at runtime, the following mapping and Person
is being used together successfully:
<property name="user" type="test.UserUserType">
<meta attribute="use-in-tostring">true</meta>
<column name="userObject" sql-type="USER_TY"/>
</property>
package test;
/**
* Person generated by hbm2java
*/
public class Person implements java.io.Serializable {
private long id;
private String name;
private long age;
private User user;
public Person() {
}
public Person(String name, long age) {
this.name = name;
this.age = age;
}
public Person(String name, long age, User user) {
this.name = name;
this.age = age;
this.user = user;
}
...
--
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
17 years, 8 months