I sucessfully setup related tables to do a cascaded insert without a problem. Now I am setting up another one and the index field (<id> field) is getting STRANGE, WEIRD values. I am using Oracle 8.1, Hibernate (tested with both 2.0.3 and 2.1b6). The column is question is the primary key, a NUMBER(10). The underlying property is a Long, set to null (as it is a new object). The generator class is set to a sequence, pointing to a value Oracle sequence. No errors are being generated when I do the .save then .flush. I have also tried this with an "increment" but saw no difference.
An example of the value that is inserted is "7E-63" but the actual value changes every time.
I am absolutely mystified. Since it is doing an insert (show_sql shows me the insert happening) it is apparent that it knows this is a new row to insert. Nothing has changed in the vehcile object, so, no other updates are occuring (which is how it should be).
I am completely mystified. I cannot "see" what values are being inserted, is there some way to enable this? The sql that I see executing is...
To retrieve the data...
Code:
Hibernate: select vehicle0_.equipId as x0_0_ from ACES_EQUIPMENTLIST vehicle0_ where (tag=? )
Hibernate: select vehicle0_.equipId as equipId, vehicle0_.TAG as TAG, vehicle0_.TYPE as TYPE, vehicle0_.HOME as HOME, vehicle0_.SITE as SITE, vehicle0_.STATUS as STATUS, vehicle0_.SITE_UNDO as SITE_UNDO, vehicle0_.STATUS_UNDO as STATUS_U8_, vehicle0_.RETIRED as RETIRED, vehicle0_.TAG as f0_, vehicle0_.SITE as f1_, vehicle0_.SITE as f2_, vehicle0_.STATUS as f3_ from ACES_EQUIPMENTLIST vehicle0_ where vehicle0_.equipId=?
Hibernate: select aces_all0_.commentId as commentId__, user1_.userId as userId0_, user1_.USERNAME as USERNAME0_, user1_.FNAME as FNAME0_, user1_.LNAME as LNAME0_, user1_.HOMESITE as HOMESITE0_, user1_.SORTORDER as SORTORDER0_, aces_all0_.commentId as commentId1_, aces_all0_.EQUIPID as EQUIPID1_, aces_all0_.USERID as USERID1_, aces_all0_.COMMENTS as COMMENTS1_, aces_all0_.COMMENTS_DATE as COMMENTS5_1_ from ACES_ALLCOMMENTS aces_all0_, ACES_USERS user1_ where aces_all0_.EQUIPID=? and aces_all0_.USERID=user1_.userId(+) order by aces_all0_.COMMENTS_DATE DESC
Hibernate: select aces_use0_.roleId as roleId__, aces_use0_.roleId as roleId, aces_use0_.USERID as USERID, aces_use0_.ROLE as ROLE from ACES_USERROLES aces_use0_ where aces_use0_.USERID=?
Hibernate: select aces_use0_.roleId as roleId__, aces_use0_.roleId as roleId, aces_use0_.USERID as USERID, aces_use0_.ROLE as ROLE from ACES_USERROLES aces_use0_ where aces_use0_.USERID=?
To insert the new row
Code:
Hibernate: select aces_seq_comments_id.nextval from dual
Hibernate: insert into ACES_ALLCOMMENTS (EQUIPID, USERID, COMMENTS, COMMENTS_DATE, commentId) values (?, ?, ?, ?, ?)
I have tried stopping and starting Tomcat. I have tried everything I can think of.
Any help is appreciated. Code that I thought made sense to include is below.
Thanks,
Kevin
-----------
The .hbm.xml file
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="fmtnm.aces.entities.Vehicle" table="ACES_EQUIPMENTLIST">
<id name="equipId">
<generator class="sequence">
<param name="sequence">aces_seq_equipment_id</param>
</generator>
</id>
<property name="tag">
<column name="TAG"/>
</property>
<property name="newTag" insert="false" update="false"
formula="TAG"/>
<property name="type" >
<column name="TYPE"/>
</property>
<property name="home" >
<column name="HOME"/>
</property>
<property name="site" >
<column name="SITE"/>
</property>
<property name="siteOrig" insert="false" update="false"
formula="SITE"/>
<property name="prevSite" insert="false" update="false"
formula="SITE"/>
<property name="status" >
<column name="STATUS"/>
</property>
<property name="statusOrig" insert="false" update="false"
formula="STATUS"/>
<property name="siteUndo" >
<column name="SITE_UNDO"/>
</property>
<property name="statusUndo" >
<column name="STATUS_UNDO"/>
</property>
<property name="retired" >
<column name="RETIRED"/>
</property>
<bag name="comments" inverse="true"
order-by="COMMENTS_DATE DESC" cascade="all-delete-orphan">
<key column="EQUIPID"/>
<one-to-many class="fmtnm.aces.entities.Comment"/>
</bag>
</class>
<class name="fmtnm.aces.entities.Comment" table="ACES_ALLCOMMENTS">
<id name="commentId">
<generator class="sequence">
<param name="sequence">aces_seq_comments_id</param>
</generator>
</id>
<many-to-one name="equipment" class="fmtnm.aces.entities.Vehicle" column="EQUIPID"/>
<many-to-one name="user" class="fmtnm.aces.entities.User" column="USERID"/>
<property name="comment">
<column name="COMMENTS"/>
</property>
<property name="date">
<column name="COMMENTS_DATE"/>
</property>
</class>
</hibernate-mapping>
Comment.java
Code:
package fmtnm.aces.entities;
public class Comment implements Serializable {
private Long olCommentId = null;
private Vehicle oEquipment = null;
private User oUser = null;
private Timestamp tsDate = null;
private String sComment = "";
public Comment() {}
public Comment(User oUser,Vehicle oEquipment, String sComment) {
this.oUser = oUser;
this.oEquipment = oEquipment;
this.sComment = sComment;
tsDate = new Timestamp(System.currentTimeMillis());
}
public void setDate(Timestamp dtNewVal) {
tsDate = dtNewVal;
}
public Timestamp getDate() {
return (tsDate);
}
public String getComment() {
return sComment;
}
public void setComment(String string) {
sComment = string;
}
public Vehicle getEquipment() {
return oEquipment;
}
public void setEquipment(Vehicle newval) {
oEquipment = newval;
}
public User getUser() {
return oUser;
}
public void setUser(User newval) {
oUser = newval;
}
public Long getCommentId() {
return olCommentId;
}
public void setCommentId(Long newval) {
olCommentId = newval;
}
}
Code where I add a vehicle
Code:
session = HibernateFactory.getSessionFactory().openSession();
Query query =
session.createQuery("SELECT o FROM fmtnm.aces.entities.Vehicle o where tag=:tag");
query.setString("tag", "E27979");
for (Iterator it = query.iterate(); it.hasNext();) {
Vehicle v = (Vehicle)it.next();
User insertUser = (User)session.load(User.class,getCurUser().
getUserId());
v.addComment(new Comment(insertUser,v,"New Comment"));
v.describe();
session.update(v);
session.flush();
}
session.close();
Snippit of Vehicle.java
Code:
package fmtnm.aces.entities;
public class Vehicle implements Serializable {
private Long olEquipId = null;
private Collection comments;
public Collection getComments() {
return (comments);
}
public void setComments(Collection comments) {
this.comments = comments;
}
public void addComment(Comment comment) {
comments.add(comment);
}
public Long getEquipId() {
return olEquipId;
}
public void setEquipId(Long newval) {
olEquipId = newval;
}
}