class:
/*
* Address.java Created on Sep 7, 2003 12:08:10 AM
*/
package com.litriusgroup.bcp.mailer.hibernate;
/**
* Hibernate persistance class for email addresses.
*/
public class Address {
/** Database uid for an address record. */
private Integer id = null;
/** address to be persisted */
private String address = null;
/**
* Set the uid for this entry.
* @param id Integer representing uid.
*/
public void setId( Integer id ){
this.id = id;
}
/**
* Obtain the uid for this address entry.
* @return Integer representing Id.
*/
public Integer getId( ){
return id;
}
/**
* Set the email address for this entry.
* @param add String representing address.
*/
public void setAddress( String add ){
address = add;
}
/**
* Obtain the address for this record.
* @return String representing address.
*/
public String getAddress( ){
return address;
}
}
mapping:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="com.litriusgroup.bcp.mailer.hibernate.Address"
table="bcp_address_bank"
discriminator-value="A">
<id name="id" type="integer" column="uid">
<!-- make sure to test out the native generator -->
<generator class="net.sf.hibernate.id.SequenceGenerator">
<param name="sequence">addbank_uid_sequence</param>
</generator>
</id>
<property name="address" column="address" type="string"/>
</class>
</hibernate-mapping>
using the class:
/*
* Test.java Created on Sep 7, 2003 11:33:42 AM
*/
package com.litriusgroup.bcp.mailer.hibernate;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;
public class Test {
Configuration hibconf = null;
SessionFactory sessions = null;
Session sess = null;
public Test() throws HibernateException{
hibconf = new Configuration();
hibconf.addFile( "/development/workspace/listmanager/etc/hibernate/obj-mapping.hbm.xml");
sessions = hibconf.buildSessionFactory();
sess = sessions.openSession();
//Transaction trans = sess.beginTransaction();
Address add = new Address();
add.setAddress( "test@domain.com" );
sess.save( add );
sess.flush();
//trans.commit();
sess.close();
}
public static void main( String[] args ) throws HibernateException{
Test tester = new Test();
}
}
my debug info:
09:10:26,719 INFO Environment:403 - Hibernate 2.0.3
09:10:26,778 INFO Environment:437 - loaded properties from resource hibernate.properties: {hibernate.connection.driver_class=org.postgresql.Driver, hibernate.cglib.use_reflection_optimizer=true, hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect, hibernate.connection.username=xxxxxxx, hibernate.connection.url=jdbc:postgresql://xxxxxxx:5432/xxxxxxxx, hibernate.show_sql=true, hibernate.connection.password=xxxxxx, hibernate.connection.pool_size=4, hibernate.statement_cache.size=20}
09:10:26,785 INFO Environment:452 - using CGLIB reflection optimizer
09:10:26,789 INFO Environment:462 - JVM proxy support: true
09:10:26,798 INFO Configuration:153 - Mapping file: /development/workspace/listmanager/etc/hibernate/obj-mapping.hbm.xml
09:10:28,120 DEBUG DTDEntityResolver:20 - trying to locate
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath under net/sf/hibernate/
09:10:28,124 DEBUG DTDEntityResolver:29 - found
http://hibernate.sourceforge.net/hibern ... ng-2.0.dtd in classpath
09:10:28,550 INFO Binder:178 - Mapping class: com.litriusgroup.bcp.mailer.hibernate.Address -> bcp_address_bank
09:10:28,740 DEBUG Binder:394 - Mapped property: id -> uid, type: integer
09:10:28,779 DEBUG Binder:394 - Mapped property: address -> address, type: string
09:10:28,781 INFO Configuration:492 - processing one-to-many association mappings
09:10:28,782 INFO Configuration:503 - processing foreign key constraints
09:10:29,186 INFO SessionFactoryImpl:132 - building session factory
09:10:29,188 DEBUG SessionFactoryImpl:134 - instantiating session factory with properties: {java.runtime.name=Java(TM) 2 Runtime Environment, Standard Edition, hibernate.connection.password=xxxxxx, sun.boot.library.path=/usr/java/j2sdk1.4.1_02/jre/lib/i386, java.vm.version=1.4.1_02-b06, hibernate.connection.username=xxxxxxxxxxxx, 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=unknown, java.vm.specification.name=Java Virtual Machine Specification, user.dir=/development/workspace/listmanager, java.runtime.version=1.4.1_02-b06, java.awt.graphicsenv=sun.awt.X11GraphicsEnvironment, java.endorsed.dirs=/usr/java/j2sdk1.4.1_02/jre/lib/endorsed, os.arch=i386, java.io.tmpdir=/tmp, line.separator=
, java.vm.specification.vendor=Sun Microsystems Inc., os.name=Linux, sun.java2d.fontpath=, java.library.path=/usr/java/j2sdk1.4.1_02/jre/lib/i386/client:/usr/java/j2sdk1.4.1_02/jre/lib/i386:/usr/java/j2sdk1.4.1_02/jre/../lib/i386:/usr/java/j2sdk1.4.2/jre/lib/i386/client:/usr/java/j2sdk1.4.2/jre/lib/i386:/usr/java/j2sdk1.4.2/jre/../lib/i386, java.specification.name=Java Platform API Specification, java.class.version=48.0, hibernate.connection.pool_size=4, java.util.prefs.PreferencesFactory=java.util.prefs.FileSystemPreferencesFactory, os.version=2.4.20-19.9custom, user.home=/home/jwickard, user.timezone=America/Chicago, java.awt.printerjob=sun.print.PSPrinterJob, file.encoding=UTF-8, java.specification.version=1.4, hibernate.connection.driver_class=org.postgresql.Driver, user.name=jwickard, java.class.path=/development/workspace/listmanager/bin:/development/workspace/listmanager/lib/commons-logging.jar:/development/workspace/listmanager/lib/bcp.jar:/development/workspace/listmanager/lib/hibernate2.jar:/usr/java/hibernate-2.0.3/lib/commons-lang.jar:/usr/java/hibernate-2.0.3/lib/dom4j.jar:/usr/java/hibernate-2.0.3/lib/ant.jar:/usr/java/hibernate-2.0.3/lib/c3p0.jar:/usr/java/hibernate-2.0.3/lib/cglib-asm.jar:/usr/java/hibernate-2.0.3/lib/commons-beanutils.jar:/usr/java/hibernate-2.0.3/lib/commons-collections.jar:/usr/java/hibernate-2.0.3/lib/commons-dbcp.jar:/usr/java/hibernate-2.0.3/lib/commons-logging.jar:/usr/java/hibernate-2.0.3/lib/commons-pool.jar:/usr/java/hibernate-2.0.3/lib/connector.jar:/usr/java/hibernate-2.0.3/lib/jaas.jar:/usr/java/hibernate-2.0.3/lib/jcs.jar:/usr/java/hibernate-2.0.3/lib/jdbc2_0-stdext.jar:/usr/java/hibernate-2.0.3/lib/jta.jar:/usr/java/hibernate-2.0.3/lib/junit.jar:/usr/java/hibernate-2.0.3/lib/odmg.jar:/usr/java/hibernate-2.0.3/lib/optional.jar:/usr/java/hibernate-2.0.3/lib/proxool.jar:/usr/java/hibernate-2.0.3/lib/xalan.jar:/usr/java/hibernate-2.0.3/lib/xerces.jar:/usr/java/hibernate-2.0.3/lib/xml-apis.jar:/development/workspace/listmanager/lib/pg73b1jdbc3.jar:/development/workspace/listmanager/etc/properties:/development/workspace/listmanager/lib/log4j-1.2.7.jar, hibernate.show_sql=true, java.vm.specification.version=1.0, sun.arch.data.model=32, java.home=/usr/java/j2sdk1.4.1_02/jre, hibernate.connection.url=jdbc:postgresql://xxxxxxxx:5432/lxxxxxxxx, hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect, java.specification.vendor=Sun Microsystems Inc., user.language=en, java.vm.info=mixed mode, hibernate.cglib.use_reflection_optimizer=true, java.version=1.4.1_02, java.ext.dirs=/usr/java/j2sdk1.4.1_02/jre/lib/ext, sun.boot.class.path=/usr/java/j2sdk1.4.1_02/jre/lib/rt.jar:/usr/java/j2sdk1.4.1_02/jre/lib/i18n.jar:/usr/java/j2sdk1.4.1_02/jre/lib/sunrsasign.jar:/usr/java/j2sdk1.4.1_02/jre/lib/jsse.jar:/usr/java/j2sdk1.4.1_02/jre/lib/jce.jar:/usr/java/j2sdk1.4.1_02/jre/lib/charsets.jar:/usr/java/j2sdk1.4.1_02/jre/classes, java.vendor=Sun Microsystems Inc., file.separator=/, java.vendor.url.bug=http://java.sun.com/cgi-bin/bugreport.cgi, hibernate.statement_cache.size=20, sun.cpu.endian=little, sun.io.unicode.encoding=UnicodeLittle, sun.cpu.isalist=}
09:10:29,224 INFO Dialect:83 - Using dialect: net.sf.hibernate.dialect.PostgreSQLDialect
09:10:29,240 INFO DriverManagerConnectionProvider:41 - Hibernate connection pool size: 4
09:10:29,254 INFO DriverManagerConnectionProvider:70 - using driver: org.postgresql.Driver at URL: jdbc:postgresql://xxxxxx:5432/xxxxxxx
09:10:29,255 INFO DriverManagerConnectionProvider:71 - connection properties: {user=xxxxxxxxxxx, password=xxxxxx}
09:10:29,274 INFO PreparedStatementCache:60 - prepared statement cache size: 20
09:10:29,276 INFO SessionFactoryImpl:162 - Use outer join fetching: true
09:10:29,277 DEBUG DriverManagerConnectionProvider:77 - total checked-out connections: 0
09:10:29,278 DEBUG DriverManagerConnectionProvider:90 - opening new JDBC connection
09:10:29,664 DEBUG DriverManagerConnectionProvider:103 - created connection to: jdbc:postgresql://xxxxxxxxxx:5432/xxxxxxxxxxx, Isolation Level: 2
09:10:29,712 DEBUG DriverManagerConnectionProvider:117 - returning connection to pool, pool size: 1
09:10:29,714 INFO SessionFactoryImpl:185 - Use scrollable result sets: true
09:10:29,715 INFO SessionFactoryImpl:186 - JDBC 2 max batch size: 15
09:10:29,727 INFO SessionFactoryImpl:194 - echoing all SQL to stdout
09:10:30,888 DEBUG SessionFactoryObjectFactory:39 - initializing class SessionFactoryObjectFactory
09:10:30,906 DEBUG SessionFactoryObjectFactory:76 - registered: ff808081f7818a0700f7818a0f5f0000 (unnamed)
09:10:30,907 INFO SessionFactoryObjectFactory:82 - no JDNI name configured
09:10:30,909 INFO SessionFactoryImpl:269 - Query language substitutions: {}
09:10:30,910 DEBUG SessionFactoryImpl:281 - instantiated session factory
09:10:31,014 DEBUG SessionImpl:413 - opened session
09:10:31,023 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
09:10:31,024 DEBUG DriverManagerConnectionProvider:77 - total checked-out connections: 0
09:10:31,025 DEBUG DriverManagerConnectionProvider:83 - using pooled JDBC connection, pool size: 0
09:10:31,027 DEBUG SessionFactoryImpl:526 - prepared statement get: select nextval ('addbank_uid_sequence')
09:10:31,031 DEBUG PreparedStatementCache:78 - preparing statement: select nextval ('addbank_uid_sequence')
09:10:31,113 DEBUG SequenceGenerator:70 - Sequence identifier generated: 8
09:10:31,120 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
09:10:31,123 DEBUG PreparedStatementCache:102 - recaching
09:10:31,124 DEBUG PreparedStatementCache:137 - total checked-out statements: 0
09:10:31,126 DEBUG PreparedStatementCache:138 - checked out: []
09:10:31,130 DEBUG SessionImpl:656 - saving [com.litriusgroup.bcp.mailer.hibernate.Address#8]
09:10:31,144 DEBUG SessionImpl:2011 - flushing session
09:10:31,148 DEBUG SessionImpl:2113 - Flushing entities and processing referenced collections
09:10:31,154 DEBUG SessionImpl:2397 - Processing unreferenced collections
09:10:31,156 DEBUG SessionImpl:2408 - Scheduling collection removes/(re)creates/updates
09:10:31,157 DEBUG SessionImpl:2023 - Flushed: 1 insertions, 0 updates, 0 deletions to 1 objects
09:10:31,158 DEBUG SessionImpl:2028 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
09:10:31,188 DEBUG SessionImpl:2058 - executing flush
09:10:31,189 DEBUG EntityPersister:464 - Inserting entity: com.litriusgroup.bcp.mailer.hibernate.Address#8
09:10:31,191 DEBUG BatcherImpl:166 - about to open: 0 open PreparedStatements, 0 open ResultSets
09:10:31,192 DEBUG SessionFactoryImpl:526 - prepared statement get: insert into bcp_address_bank (address, uid) values (?, ?)
09:10:31,194 DEBUG PreparedStatementCache:78 - preparing statement: insert into bcp_address_bank (address, uid) values (?, ?)
09:10:31,195 DEBUG EntityPersister:366 - Dehydrating entity: com.litriusgroup.bcp.mailer.hibernate.Address#8
09:10:31,202 DEBUG StringType:44 - binding
'test@domain.com' to parameter: 1
09:10:31,204 DEBUG IntegerType:44 - binding '8' to parameter: 2
09:10:31,205 DEBUG BatcherImpl:24 - Adding to batch
09:10:31,207 DEBUG BatcherImpl:46 - Executing batch size: 1
09:10:31,215 ERROR BatcherImpl:62 - Exception executing batch:
java.lang.ArrayIndexOutOfBoundsException: 1
at org.postgresql.core.QueryExecutor.sendQuery(QueryExecutor.java:143)
at org.postgresql.core.QueryExecutor.execute(QueryExecutor.java:65)
at org.postgresql.jdbc1.AbstractJdbc1Connection.ExecSQL(AbstractJdbc1Connection.java:451)
at org.postgresql.jdbc1.AbstractJdbc1Statement.execute(AbstractJdbc1Statement.java:281)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:48)
at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:179)
at org.postgresql.jdbc1.AbstractJdbc1Statement.executeUpdate(AbstractJdbc1Statement.java:165)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:80)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:50)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:105)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2103)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2061)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2005)
at com.litriusgroup.bcp.mailer.hibernate.Test.<init>(Test.java:37)
at com.litriusgroup.bcp.mailer.hibernate.Test.main(Test.java:44)
09:10:31,221 DEBUG BatcherImpl:173 - done closing: 0 open PreparedStatements, 0 open ResultSets
09:10:31,222 DEBUG PreparedStatementCache:102 - recaching
09:10:31,223 DEBUG PreparedStatementCache:137 - total checked-out statements: 0
09:10:31,225 DEBUG PreparedStatementCache:138 - checked out: []