]
Max Rydahl Andersen closed HBX-933.
-----------------------------------
Resolution: Rejected
There is no bug and your report makes no sense to.
access="someusertype" is wrong.
type="someusertype" is what should be used and of course if the
"someusertype" is not available on the classpath to return the proper classname
we can't do much else than assume the type is actually "someusertype"
Please use the user forum before posting non-bugs.
Property access and type utilization conflict between runtime and
code generation.
-----------------------------------------------------------------------------------
Key: HBX-933
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HBX-933
Project: Hibernate Tools
Issue Type: Bug
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: