I encountered an exception when building a session factory for a class involving a UserType, details-
Hibernate version: 3.0.1
Mapping documents:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class
name="com.yesasia.foogo.model.hibernate.DummyOrder"
table="tbl_temp_dummy_order"
proxy="false"
dynamic-update="false"
dynamic-insert="false"
select-before-update="false"
optimistic-lock="version"
>
<id name="id" column="order_id" type="long" unsaved-value="0" >
<generator class="native" />
</id>
<property name="flags" type="com.yesasia.foogo.model.hibernate.TinyintBackedBitSetUserType" update="true" insert="true" access="property">
<column name="flags" sql-type="tinyint unsigned"/>
</property>
<property name="reference" type="java.lang.String" update="true" insert="true" access="property" column="reference"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close(): Code:
SessionFactory factory = new Configuration().addProperties(Factory.hibernateProperties).addClass(DummyOrder.class).buildSessionFactory();
Full stack trace of any exception that occurs: Code:
22/04/2005 17:13:12 - INFO [main] (Environment.java:460) - Hibernate 3.0.1
22/04/2005 17:13:12 - INFO [main] (Environment.java:473) - hibernate.properties not found
22/04/2005 17:13:12 - INFO [main] (Environment.java:506) - using CGLIB reflection optimizer
22/04/2005 17:13:12 - INFO [main] (Environment.java:536) - using JDK 1.4 java.sql.Timestamp handling
22/04/2005 17:13:12 - INFO [main] (Configuration.java:461) - Mapping resource: DummyOrder.hbm.xml
22/04/2005 17:13:12 - DEBUG [main] (DTDEntityResolver.java:42) - trying to locate http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd in classpath under org/hibernate/
22/04/2005 17:13:12 - DEBUG [main] (DTDEntityResolver.java:53) - found http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd in classpath
22/04/2005 17:13:12 - INFO [main] (HbmBinder.java:258) - Mapping class: DummyOrder -> tbl_temp_dummy_order
22/04/2005 17:13:12 - DEBUG [main] (HbmBinder.java:1089) - Mapped property: id -> order_id
22/04/2005 17:13:12 - DEBUG [main] (HbmBinder.java:1089) - Mapped property: flags -> flags
22/04/2005 17:13:12 - DEBUG [main] (HbmBinder.java:1089) - Mapped property: reference -> reference
22/04/2005 17:13:12 - DEBUG [main] (Configuration.java:1048) - Preparing to build session factory with filters : {}
22/04/2005 17:13:12 - INFO [main] (Configuration.java:852) - processing extends queue
22/04/2005 17:13:12 - INFO [main] (Configuration.java:856) - processing collection mappings
22/04/2005 17:13:12 - INFO [main] (Configuration.java:865) - processing association property references
22/04/2005 17:13:12 - INFO [main] (Configuration.java:894) - processing foreign key constraints
22/04/2005 17:13:13 - INFO [main] (Dialect.java:91) - Using dialect: org.hibernate.dialect.MySQLDialect
22/04/2005 17:13:13 - DEBUG [main] (SQLExceptionConverterFactory.java:52) - Using dialect defined converter
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:88) - Maximum outer join fetch depth: 2
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:91) - Default batch fetch size: 1
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:95) - Generate SQL with comments: disabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:99) - Order SQL updates by primary key: disabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:285) - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
22/04/2005 17:13:13 - INFO [main] (ASTQueryTranslatorFactory.java:21) - Using ASTQueryTranslatorFactory
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:107) - Query language substitutions: {}
22/04/2005 17:13:13 - INFO [main] (DriverManagerConnectionProvider.java:41) - Using Hibernate built-in connection pool (not for production use!)
22/04/2005 17:13:13 - INFO [main] (DriverManagerConnectionProvider.java:42) - Hibernate connection pool size: 20
22/04/2005 17:13:13 - INFO [main] (DriverManagerConnectionProvider.java:45) - autocommit mode: false
22/04/2005 17:13:13 - INFO [main] (DriverManagerConnectionProvider.java:80) - using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost/test?characterEncoding=utf8
22/04/2005 17:13:13 - INFO [main] (DriverManagerConnectionProvider.java:83) - connection properties: {user=test, password=na}
22/04/2005 17:13:13 - DEBUG [main] (DriverManagerConnectionProvider.java:93) - total checked-out connections: 0
22/04/2005 17:13:13 - DEBUG [main] (DriverManagerConnectionProvider.java:109) - opening new JDBC connection
22/04/2005 17:13:13 - DEBUG [main] (DriverManagerConnectionProvider.java:115) - created connection to: jdbc:mysql://localhost/test?characterEncoding=utf8, Isolation Level: 4
22/04/2005 17:13:13 - DEBUG [main] (DriverManagerConnectionProvider.java:129) - returning connection to pool, pool size: 1
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:149) - JDBC batch size: 15
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:152) - JDBC batch updates for versioned data: disabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:157) - Scrollable result sets: enabled
22/04/2005 17:13:13 - DEBUG [main] (SettingsFactory.java:161) - Wrap result sets: disabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:165) - JDBC3 getGeneratedKeys(): enabled
22/04/2005 17:13:13 - INFO [main] (TransactionFactoryFactory.java:31) - Using default transaction strategy (direct JDBC transactions)
22/04/2005 17:13:13 - INFO [main] (TransactionManagerLookupFactory.java:33) - No TransactionManagerLookup configured (in JTA environment, use of read-write or transactional second-level cache is not recommended)
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:177) - Automatic flush during beforeCompletion(): disabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:180) - Automatic session close at end of transaction: disabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:186) - Second-level cache: enabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:190) - Query cache: disabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:272) - Cache provider: org.hibernate.cache.EhCacheProvider
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:205) - Optimize cache for minimal puts: disabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:214) - Structured second-level cache entries: enabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:226) - Statistics: disabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:230) - Deleted entity synthetic identifier rollback: disabled
22/04/2005 17:13:13 - INFO [main] (SettingsFactory.java:244) - Default entity-mode: pojo
22/04/2005 17:13:13 - INFO [main] (SessionFactoryImpl.java:147) - building session factory
22/04/2005 17:13:13 - DEBUG [main] (SessionFactoryImpl.java:156) - Session factory constructed with filter configurations : {}
22/04/2005 17:13:13 - DEBUG [main] (SessionFactoryImpl.java:159) - instantiating session factory with properties: {hibernate.connection.password=test, java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, sun.boot.library.path=C:\Program Files\Java\j2re1.4.2_07\bin, java.vm.version=1.4.2_07-b05, hibernate.connection.username=test, java.vm.vendor=Sun Microsystems Inc., java.vendor.url=http://java.sun.com/, path.separator=;, java.vm.name=Java HotSpot(TM) Client VM, file.encoding.pkg=sun.io, user.country=US, sun.os.patch.level=Service Pack 4, java.vm.specification.name=Java Virtual Machine Specification, user.dir=D:\maven-workspace\test\model, java.runtime.version=1.4.2_07-b05, java.awt.graphicsenv=sun.awt.Win32GraphicsEnvironment, java.endorsed.dirs=C:\Program Files\Java\j2re1.4.2_07\lib\endorsed, os.arch=x86, java.io.tmpdir=C:\DOCUME~1\teay\LOCALS~1\Temp\, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., user.variant=, os.name=Windows 2000, sun.java2d.fontpath=, java.library.path=C:\Program Files\Java\j2re1.4.2_07\bin;.;C:\WINNT\system32;C:\WINNT;C:\WINNT\system32;C:\WINNT;C:\WINNT\System32\Wbem;C:\Program Files\Microsoft SQL Server\80\Tools\BINN;C:\Program Files\cvsnt;C:\WINNT\System32;C:\j2sdk1.4.2_07\bin;C:\Program Files\Apache Software Foundation\Maven 1.0.2\bin;C:\Program Files\Apache Software Foundation\Maven 1.0.2\bin;;C:\Program Files\McAfee\Managed VirusScan\VScan, java.specification.name=Java Platform API Specification, java.class.version=48.0, java.util.prefs.PreferencesFactory=java.util.prefs.WindowsPreferencesFactory, os.version=5.0, user.home=C:\Documents and Settings\teay, user.timezone=GMT+08:00, java.awt.printerjob=sun.awt.windows.WPrinterJob, file.encoding=Cp1252, java.specification.version=1.4, hibernate.connection.driver_class=com.mysql.jdbc.Driver, user.name=teay, java.class.path=/c:/Program Files/eclipse/3.1M4/plugins/org.eclipse.jdt.junit_3.1.0/junitsupport.jar;/c:/Program Files/eclipse/3.1M4/plugins/org.eclipse.jdt.junit.runtime_3.1.0/junitruntime.jar;D:\maven-workspace\test\model\bin;C:\Documents and Settings\teay\.maven\repository\junit\jars\junit-3.8.1.jar;C:\Documents and Settings\teay\.maven\repository\commons-logging\jars\commons-logging-1.0.4.jar;C:\Documents and Settings\teay\.maven\repository\commons-lang\jars\commons-lang-2.0.jar;C:\Documents and Settings\teay\.maven\repository\commons-io\jars\commons-io-1.0.jar;C:\Documents and Settings\teay\.maven\repository\commons-collections\jars\commons-collections-3.1.jar;C:\Documents and Settings\teay\.maven\repository\bcel\jars\bcel-5.1.jar;C:\Documents and Settings\teay\.maven\repository\mysql\jars\mysql-connector-java-3.0.10-stable-bin.jar;C:\Documents and Settings\teay\.maven\repository\jta\jars\jta-1.0.1.jar;C:\Documents and Settings\teay\.maven\repository\dbunit\jars\dbunit-2.1.jar;C:\Documents and Settings\teay\.maven\repository\tomcat\jars\servlet-api-5.0.16.jar;D:\maven-workspace\test\commons\bin;C:\Documents and Settings\teay\.maven\repository\log4j\jars\log4j-1.2.8.jar;C:\Documents and Settings\teay\.maven\repository\dom4j\jars\dom4j-1.5.2.jar;C:\Documents and Settings\teay\.maven\repository\odmg\jars\odmg-3.0.jar;C:\Documents and Settings\teay\.maven\repository\ehcache\jars\ehcache-0.9.jar;C:\Documents and Settings\teay\.maven\repository\cglib\jars\cglib-full-2.0.2.jar;C:\Documents and Settings\teay\.maven\repository\velocity\jars\velocity-1.4.jar;C:\Documents and Settings\teay\.maven\repository\javamail\jars\mail-1.3.2.jar;C:\Documents and Settings\teay\.maven\repository\jaf\jars\activation-1.0.2.jar;C:\Documents and Settings\teay\.maven\repository\springframework\jars\spring-1.2-rc1.jar;C:\Documents and Settings\teay\.maven\repository\test\jars\model-0.1-b1.jar;C:\Documents and Settings\teay\.maven\repository\dom4j\jars\dom4j-1.6.jar;C:\Documents and Settings\teay\.maven\repository\cglib\jars\cglib-2.1.jar;C:\Documents and Settings\teay\.maven\repository\ehcache\jars\ehcache-1.1.jar;C:\Documents and Settings\teay\.maven\repository\springframework\jars\spring-1.2-rc2.jar;C:\Documents and Settings\teay\.maven\repository\hibernate\jars\hibernate-3.0.1.jar;C:\Documents and Settings\teay\.maven\repository\antlr\jars\antlr-2.7.5H3.jar;C:\Documents and Settings\teay\.maven\repository\log4j\jars\log4j-1.2.9.jar;C:\Documents and Settings\teay\.maven\repository\asm\jars\asm-2.0.RC1.jar;C:\Documents and Settings\teay\.maven\repository\asm\jars\asm-attrs-2.0.RC1.jar;C:\Documents and Settings\teay\.maven\repository\xerces\jars\xerces-2.6.2.jar, java.vm.specification.version=1.0, java.home=C:\Program Files\Java\j2re1.4.2_07, sun.arch.data.model=32, hibernate.connection.url=jdbc:mysql://localhost/test?characterEncoding=utf8, hibernate.dialect=org.hibernate.dialect.MySQLDialect, user.language=en, java.specification.vendor=Sun Microsystems Inc., awt.toolkit=sun.awt.windows.WToolkit, hibernate.cglib.use_reflection_optimizer=true, java.vm.info=mixed mode, java.version=1.4.2_07, java.ext.dirs=C:\Program Files\Java\j2re1.4.2_07\lib\ext, sun.boot.class.path=C:\Program Files\Java\j2re1.4.2_07\lib\rt.jar;C:\Program Files\Java\j2re1.4.2_07\lib\i18n.jar;C:\Program Files\Java\j2re1.4.2_07\lib\sunrsasign.jar;C:\Program Files\Java\j2re1.4.2_07\lib\jsse.jar;C:\Program Files\Java\j2re1.4.2_07\lib\jce.jar;C:\Program Files\Java\j2re1.4.2_07\lib\charsets.jar;C:\Program Files\Java\j2re1.4.2_07\classes, java.vendor=Sun Microsystems Inc., file.separator=\, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.endian=little, sun.cpu.isalist=pentium i486 i386}
22/04/2005 17:13:13 - WARN [main] (Configurator.java:125) - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Documents%20and%20Settings/teay/.maven/repository/ehcache/jars/ehcache-0.9.jar!/ehcache-failsafe.xml
java.lang.NullPointerException
at org.hibernate.tuple.PojoTuplizer.buildProxyFactory(PojoTuplizer.java:103)
at org.hibernate.tuple.AbstractTuplizer.<init>(AbstractTuplizer.java:83)
at org.hibernate.tuple.PojoTuplizer.<init>(PojoTuplizer.java:54)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:47)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:217)
at org.hibernate.persister.entity.BasicEntityPersister.<init>(BasicEntityPersister.java:401)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:104)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:206)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1055)
at TestTinyintBackedBitSetUserType.<clinit>(TestTinyintBackedBitSetUserType.java:34)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at junit.framework.TestSuite.createTest(TestSuite.java:135)
at junit.framework.TestSuite.addTestMethod(TestSuite.java:114)
at junit.framework.TestSuite.<init>(TestSuite.java:75)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.getTest(RemoteTestRunner.java:397)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:441)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:194)
22/04/2005 17:13:14 - INFO [Finalizer] (DriverManagerConnectionProvider.java:147) - cleaning up connection pool: jdbc:mysql://localhost/test?characterEncoding=utf8
Name and version of the database you are using: MySQL 4.1.11 (InnoDB)
The generated SQL (show_sql=true):NA
Debug level Hibernate log excerpt:pls see above
Collaborating classCode:
/**
* dummy order for testing
*/
public class DummyOrder implements Serializable {
private long id;
private ExtendedBitSet flags;
public DummyOrder() {
super();
}
public ExtendedBitSet getFlags() {
return flags;
}
public void setFlags(ExtendedBitSet flags) {
this.flags = flags;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
}
Code:
/**
* mapping ExtendedBitSet to tinyint
*/
public class TinyintBackedBitSetUserType implements UserType {
private static final int[] SQL_TYPES = { Types.TINYINT };
public TinyintBackedBitSetUserType() {
super();
}
public int[] sqlTypes() {
return new int[] { SQL_TYPES };
}
public IntBackedBitSetUserTypeA() {
super();
}
public Class returnedClass() {
return ExtendedBitSet.class;
}
public boolean equals(Object x, Object y) throws HibernateException {
if (x == y) {
return true;
}
if (x == null || y == null) {
return false;
}
return x.equals(y);
}
public int hashCode(Object obj) throws HibernateException {
System.out.println("hashCode: obj was null!");
return obj.hashCode();
}
public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
throws HibernateException, SQLException {
if (resultSet.wasNull()) {
return null;
}
int i = resultSet.getInt(names[0]);
return new ExtendedBitSet(i, 32);
}
public void nullSafeSet(PreparedStatement statement, Object value, int index)
throws HibernateException, SQLException {
if (value == null) {
statement.setNull(index, getSQLType());
} else {
final ExtendedBitSet bits = (ExtendedBitSet) value;
statement.setInt(index, (int) bits.toLong());
}
}
protected abstract void setStatementValue(PreparedStatement statement,
Object value, int index) throws SQLException;
public Object deepCopy(Object obj) throws HibernateException {
if (obj == null) {
return null;
}
return ((ExtendedBitSet) obj).clone();
}
public boolean isMutable() {
return true;
}
public Serializable disassemble(Object value) throws HibernateException {
if (value == null) {
return null;
}
return (Serializable) ((ExtendedBitSet) value).clone();
}
public Object assemble(Serializable cached, Object owner)
throws HibernateException {
if (cached == null) {
return null;
}
return ((ExtendedBitSet) cached).clone();
}
public Object replace(Object original, Object target, Object owner)
throws HibernateException {
if (original == null) {
return null;
}
return ((ExtendedBitSet) original).clone();
}
}
Any clue will be highly appreciated, thanks!!