-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: having problem with one-to-many relationship
PostPosted: Thu Sep 29, 2005 9:41 pm 
Newbie

Joined: Thu Sep 29, 2005 9:21 pm
Posts: 2
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:hibernate 3.0

Mapping documents:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="EventDO" table="EVENT_LOG_HEADER_TBL">

<id name="id" column="EVENT_LOG_HEADER_ID" type="long">
<generator class="sequence">
<param name="sequence">EVENT_LOG_HEADER_TBL_SEQ</param>
</generator>
</id>
<property name="eventId">
<column name="EVENT_ID" not-null="true"/>
</property>
<property name="sessionId">
<column name="SESSION_ID" length="254" not-null="true"/>
</property>
<property name="userId">
<column name="USER_ID" length="20" not-null="true"/>
</property>
<property name="userType">
<column name="USER_TYPE" length="30" not-null="true"/>
</property>
<set name="eventDetails" cascade="all" inverse="true" lazy="true">
<key column="EVENT_LOG_HEADER_ID"/>
<one-to-many class="EventDetailDO"/>
</set>
</class>


</hibernate-mapping>


<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

<hibernate-mapping>

<class name="EventDetailDO" table="EVENT_LOG_DETAIL_TBL">

<id name="id" column="ID" type="long">
<generator class="sequence">
<param name="sequence">EVENT_LOG_DETAIL_TBL_SEQ</param>
</generator>
</id>
<property name="name">
<column name="NAME" length="30" not-null="true"/>
</property>
<property name="value">
<column name="VALUE" length="40" not-null="false"/>
</property>
<many-to-one name="event" class="EventDO" column="EVENT_LOG_HEADER_ID" not-null="true"/>
</class>

</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():

try {
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
for(int i=0;i<al.size();i++){
session.save(al.get(i));
}
tx.commit();

}
catch (Exception he){
he.printStackTrace();
throw new RemoteException();
}
finally {
try{
HibernateUtil.closeSession();
}catch (Exception he){
he.printStackTrace();
throw new RemoteException();
}

}
}


Classes use for mapping
public class EventDO implements Serializable{
private long id;
private long eventId;
private String userId;
private String userType;
private String sessionId;
private Set eventDetails;

public EventDO() {

}

public long getId() {
return id;
}

public void setId(long argId) {
this.id = argId;
}

public long getEventId() {
return eventId;
}

public void setEventId(long argEventId) {
this.eventId = argEventId;
}

public String getUserId() {
return userId;
}

public void setUserId(String argUserId) {
this.userId = argUserId;
}

public String getUserType() {
return userType;
}

public void setUserType(String argUserType) {
this.userType = argUserType;
}

public Set getEventDetails() {
return eventDetails;
}

public void setEventDetails(Set argEventDetails) {
this.eventDetails = argEventDetails;
}

public String getSessionId() {
return sessionId;
}

public void setSessionId(String argSessionId) {
this.sessionId = argSessionId;
}


}

public class EventDetailDO implements Serializable{
private long id;
private EventDO event;
private String name;
private String value;


public EventDetailDO() {

}

public long getId() {
return id;
}

public void setId(long argId) {
this.id = argId;
}

public EventDO getEvent() {
return event;
}

public void setEvent(EventDO argEvent) {
this.event = argEvent;
}

public String getName() {
return name;
}

public void setName(String argName) {
this.name = argName;
}

public String getValue() {
return value;
}

public void setValue(String argValue) {
this.value = argValue;
}

Full stack trace of any exception that occurs:


[[INFO] Environment - Hibernate 3.0.5
[INFO] Environment - hibernate.properties not found
[INFO] Environment - using CGLIB reflection optimizer
[INFO] Environment - JVM does not support Statement.getGeneratedKeys()
[INFO] Environment - JVM does not support LinkedHasMap, LinkedHashSet - ordered maps and sets disabled
[INFO] Environment - using workaround for JVM bug in java.sql.Timestamp
[INFO] Environment - using pre JDK 1.4 java.sql.Timestamp handling
[INFO] Configuration - configuring from resource: /hibernate.cfg.xml
[INFO] Configuration - Configuration resource: /hibernate.cfg.xml
[INFO] Configuration - Mapping resource: EventHeader.hbm.xml
[INFO] HbmBinder - Mapping class: EventDO -> EVENT_LOG_HEADER_TBL
[INFO] Configuration - Mapping resource: EventDetail.hbm.xml
[INFO] HbmBinder - Mapping class: EventDetailDO -> EVENT_LOG_DETAIL_TBL
[INFO] Configuration - Configured SessionFactory: hibernate_SessionFactory
[INFO] Configuration - processing extends queue
[INFO] Configuration - processing collection mappings
[INFO] HbmBinder - Mapping collection: EventDO.eventDetails -> EVENT_LOG_DETAIL_TBL
[INFO] Configuration - processing association property references
[INFO] Configuration - processing foreign key constraints
[INFO] NamingHelper - JNDI InitialContext properties:{}
[INFO] DatasourceConnectionProvider - Using datasource: weblogic.jdbc.jts.dataSyncPool
[INFO] SettingsFactory - RDBMS: Oracle, version: Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production
[INFO] SettingsFactory - JDBC driver: Oracle JDBC driver, version: 9.2.0.2.0
[INFO] Dialect - Using dialect: org.hibernate.dialect.Oracle9Dialect
[INFO] TransactionFactoryFactory - Transaction strategy: org.hibernate.transaction.JTATransactionFactory
[INFO] NamingHelper - JNDI InitialContext properties:{}
[INFO] TransactionManagerLookupFactory - instantiating TransactionManagerLookup: org.hibernate.transaction.WeblogicTransactionManagerLookup
[INFO] TransactionManagerLookupFactory - instantiated TransactionManagerLookup
[INFO] TransactionManagerLookupFactory - instantiating TransactionManagerLookup: org.hibernate.transaction.WeblogicTransactionManagerLookup
[INFO] TransactionManagerLookupFactory - instantiated TransactionManagerLookup
[INFO] SettingsFactory - Automatic flush during beforeCompletion(): disabled
[INFO] SettingsFactory - Automatic session close at end of transaction: disabled
[INFO] SettingsFactory - JDBC batch size: 15
[INFO] SettingsFactory - JDBC batch updates for versioned data: disabled
[INFO] SettingsFactory - Scrollable result sets: enabled
[INFO] SettingsFactory - JDBC3 getGeneratedKeys(): disabled
[INFO] SettingsFactory - Connection release mode: null
[INFO] SettingsFactory - Default batch fetch size: 1
[INFO] SettingsFactory - Generate SQL with comments: disabled
[INFO] SettingsFactory - Order SQL updates by primary key: disabled
[INFO] SettingsFactory - Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
[INFO] ASTQueryTranslatorFactory - Using ASTQueryTranslatorFactory
[INFO] SettingsFactory - Query language substitutions: {}
[INFO] SettingsFactory - Second-level cache: enabled
[INFO] SettingsFactory - Query cache: disabled
[INFO] SettingsFactory - Cache provider: org.hibernate.cache.EhCacheProvider
[INFO] SettingsFactory - Optimize cache for minimal puts: disabled
[INFO] SettingsFactory - Structured second-level cache entries: disabled
[INFO] SettingsFactory - Echoing all SQL to stdout
[INFO] SettingsFactory - Statistics: disabled
[INFO] SettingsFactory - Deleted entity synthetic identifier rollback: disabled
[INFO] SettingsFactory - Default entity-mode: pojo
[INFO] SessionFactoryImpl - building session factory
[WARN] Configurator - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/C:/Audit_Reports/cpDomain/lib/hibernate/ehcache-1.1.jar!/e
[INFO] SessionFactoryObjectFactory - Factory name: hibernate_SessionFactory
[INFO] NamingHelper - JNDI InitialContext properties:{}
[INFO] SessionFactoryObjectFactory - Bound factory to JNDI name: hibernate_SessionFactory
[WARN] SessionFactoryObjectFactory - InitialContext did not implement EventContext
[INFO] NamingHelper - JNDI InitialContext properties:{}
[INFO] SessionFactoryImpl - Checking 0 named queries
Session created org.hibernate.impl.SessionImpl(PersistenceContext[entityKeys=[],collectionKeys=[]] ActionQueue[insertions=[] updates=[] deletions=[] collectionCreations=[] collectionRe
Hibernate: select EVENT_LOG_HEADER_TBL_SEQ.nextval from dual
Hibernate: select EVENT_LOG_DETAIL_TBL_SEQ.nextval from dual
org.hibernate.PropertyValueException: not-null property references a null or transient value: EventDetailDO.event
at org.hibernate.engine.Nullability.checkNullability(Nullability.java:72)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:236)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:96)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:468)
at org.hibernate.engine.Cascades$5.cascade(Cascades.java:154)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:771)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascadeCollection(Cascades.java:895)
at org.hibernate.engine.Cascades.cascadeAssociation(Cascades.java:792)
at org.hibernate.engine.Cascades.cascade(Cascades.java:720)
at org.hibernate.engine.Cascades.cascade(Cascades.java:847)
at org.hibernate.event.def.AbstractSaveEventListener.cascadeAfterSave(AbstractSaveEventListener.java:363)
at org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:265)
at org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:160)
at org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:108)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:184)
at org.hibernate.event.def.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:33)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:173)
at org.hibernate.event.def.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:27)
at org.hibernate.event.def.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:69)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:481)
at org.hibernate.impl.SessionImpl.save(SessionImpl.java:476)
Name and version of the database you are using:
oracle 9i

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 10:11 pm 
Senior
Senior

Joined: Wed Jul 13, 2005 4:31 pm
Posts: 142
Location: Seattle, WA
My guess is that one of the objects being saved has a null event value.

try removing the not-null='true' for event.


Code:
<many-to-one name="event" class="EventDO" column="EVENT_LOG_HEADER_ID"/>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 29, 2005 10:44 pm 
Newbie

Joined: Thu Sep 29, 2005 9:21 pm
Posts: 2
anar wrote:
My guess is that one of the objects being saved has a null event value.

try removing the not-null='true' for event.


Code:
<many-to-one name="event" class="EventDO" column="EVENT_LOG_HEADER_ID"/>


If I remove not-null='true' it generates sql statements and it is trying to insert null into EVENT_LOG_DETAIL_TBL and it fails


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 30, 2005 12:10 am 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
do you have a not null constraint for that column in the database ?
if so you will need to specify a value for it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.