Hallo, I'm starting with Hibernate but I'm unable to store a object into
database, this is my code, mapping element and console stackTrace
Some help please.
Hibernate version: hibernate 2
Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="net.republica.admin.usuarios">
<class name="net.republica.admin.usuarios.Usuarios" table="usuarios">
<id name="id" column="id" type="long" unsaved-value="null">
<generator class="hilo"/>
</id>
<property column="estado" length="5" name="estado" not-null="true" type="long"/>
<property column="password" length="20" name="password" not-null="true" type="string"/>
<property column="nombre" length="40" name="nombre" not-null="true" type="string"/>
<property column="fecha" length="7" name="fecha" not-null="true" type="date"/>
<property column="login" length="20" name="login" not-null="true" type="string"/>
<property column="ip" length="40" name="ip" not-null="true" type="string"/>
<property column="apellidos" length="100" name="apellidos" not-null="true" type="string" />
<property column="email" length="50" name="email" not-null="true" type="string" />
<property column="telefono" length="20" name="telefono" not-null="false" type="string"/>
</class>
Code between sessionFactory.openSession() and session.close():
protected Object retrieveObj(String key, String value) throws DAOException {
List objects = retrieveObjs(key, value);
if (objects != null) {
if (objects.size() == 0) {
return null;
}
else {
return objects.get(0);
}
}
else {
return null;
}
}
protected List retrieveObjs(String key, String value) throws DAOException {
List results = null;
try {
Session session = HibernateSession.currentSession();
if (value != null) {
results = (List) session.find(getQuery(key), value, Hibernate.STRING);
}
else {
results = (List) session.find(getQuery(key));
}
}
catch (HibernateException he) {
he.printStackTrace();
throw new DAOException(he);
}
finally {
closeSession();
}
return results;
}
public Usuarios saveUsuarios(Usuarios u) throws DAOException {
System.out.println("saving users");
storeObj(u);
System.out.println("retrieveObj");
return (Usuarios) retrieveObj(Usuarios.class, u.getId());
}
protected void storeObj(Object obj) throws DAOException {
try {
Session session = HibernateSession.currentSession();
/*
///////////////////////////////////////////
*/
tx = session.beginTransaction();
session.saveOrUpdate(obj);
// session.flush();
//session.connection().commit();
tx.commit();
}
catch(HibernateException he) {
try{
tx.rollback();
}catch(HibernateException hie){
hie.printStackTrace();
}
throw new DAOException(he);
}
finally {
closeSession();
}
}
Name and version of the database you are using:Oracle 8i
Full stack trace of any exception that occurs:
19:32:57,630 INFO [TilesPlugin] Tiles definition factory loaded for module ''.
19:32:57,657 INFO [ValidatorPlugIn] Loading validation rules file from '/WEB-INF/validator-rules.xml'
19:32:57,659 INFO [ValidatorPlugIn] Loading validation rules file from '/WEB-INF/validation.xml'
19:32:59,561 INFO [TilesRequestProcessor] Tiles definition factory found for request processor ''.
19:32:59,650 INFO [STDOUT] test
19:32:59,780 INFO [Configuration] Mapping resource: net/republica/admin/usuarios/Usuarios.hbm.xml
19:32:59,907 INFO [Binder] Mapping class: net.republica.admin.usuarios.Usuarios -> usuarios
19:32:59,912 INFO [Configuration] Mapping resource: net/republica/objects/Player.hbm.xml
19:32:59,942 INFO [Binder] Mapping class: net.republica.objects.Player -> players
19:32:59,944 INFO [Configuration] Mapping resource: net/republica/objects/Team.hbm.xml
19:32:59,996 INFO [Binder] Mapping class: net.republica.objects.Team -> teams
19:32:59,999 INFO [Configuration] processing one-to-many association mappings
19:32:59,999 INFO [Binder] Mapping collection: net.republica.objects.Team.players -> players
19:33:00,000 INFO [Configuration] processing one-to-one association property references
19:33:00,000 INFO [Configuration] processing foreign key constraints
19:33:00,001 INFO [Dialect] Using dialect: net.sf.hibernate.dialect.OracleDialect
19:33:00,002 INFO [SettingsFactory] Use outer join fetching: true
19:33:00,002 INFO [NamingHelper] JNDI InitialContext properties:{}
19:33:00,026 INFO [DatasourceConnectionProvider] Using datasource: java:OracleDS
19:33:00,027 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: net.sf.hibernate.transaction.JBossTransactionManagerLookup
19:33:00,027 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
19:33:00,108 INFO [SettingsFactory] Use scrollable result sets: true
19:33:00,109 INFO [SettingsFactory] Use JDBC3 getGeneratedKeys(): false
19:33:00,109 INFO [SettingsFactory] Optimize cache for minimal puts: false
19:33:00,109 INFO [SettingsFactory] echoing all SQL to stdout
19:33:00,110 INFO [SettingsFactory] Query language substitutions: {}
19:33:00,110 INFO [SettingsFactory] cache provider: net.sf.hibernate.cache.EhCacheProvider
19:33:00,110 INFO [Configuration] instantiating and configuring caches
19:33:00,110 INFO [SessionFactoryImpl] building session factory
19:33:00,342 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
19:33:00,343 INFO [NamingHelper] JNDI InitialContext properties:{}
19:33:00,388 ERROR [TableGenerator] could not read a hi value
java.sql.SQLException: ORA-01002: b
|