-->
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.  [ 2 posts ] 
Author Message
 Post subject: Problem inserting dates/times.
PostPosted: Fri Jun 19, 2009 10:53 am 
Newbie

Joined: Wed May 27, 2009 11:43 am
Posts: 4
I'm trying to insert a date/time stamp into a Oracle database via Hibernate/Java. The XML file was generated by the NetBeans IDE and follows:

<?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">
<!-- Generated May 5, 2009 2:41:07 PM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
<class name="Database_HibernateXML.CpSample" schema="CPDCS" table="CP_SAMPLE">
<composite-id class="Database_HibernateXML.CpSampleId" name="id">
<key-property name="sampleId" type="string">
<column length="13" name="SAMPLE_ID"/>
</key-property>
<key-property name="dateTimeStamp" type="java.lang.date">
<column length="7" name="DATE_TIME_STAMP"/>
</key-property>
</composite-id>
<property name="expTest" type="string">
<column length="20" name="EXP_TEST"/>
</property>
<property name="tech" type="string">
<column length="32" name="TECH"/>
</property>
<property name="subjectTypeCode" type="big_decimal">
<column name="SUBJECT_TYPE_CODE" precision="22" scale="0"/>
</property>
<property name="subjectId" type="string">
<column length="30" name="SUBJECT_ID"/>
</property>
<property name="verified" type="string">
<column length="1" name="VERIFIED"/>
</property>
<property name="dateSampleCollected" type="java.lang.date">
<column length="7" name="DATE_SAMPLE_COLLECTED"/>
</property>
<property name="sampleComment" type="string">
<column length="2000" name="SAMPLE_COMMENT"/>
</property>
<property name="dateSampleProcessed" type="java.lang.date">
<column length="7" name="DATE_SAMPLE_PROCESSED"/>
</property>
<property name="animalIdType" type="java.lang.Character">
<column length="1" name="ANIMAL_ID_TYPE"/>
</property>
<property name="printed" type="string">
<column length="1" name="PRINTED"/>
</property>
<property name="sampleComment2" type="string">
<column length="2000" name="SAMPLE_COMMENT2"/>
</property>
<set inverse="true" name="cpResultses" table="cp_results">
<key>
<column length="13" name="SAMPLE_ID" not-null="true"/>
<column length="7" name="SAMPLE_DATE_TIME" not-null="true"/>
</key>
<one-to-many class="Database_HibernateXML.CpResults"/>
</set>
</class>
</hibernate-mapping>

The class was also generated by Netbeans and follows:

public class CpSample implements java.io.Serializable {


private CpSampleId id;
private String expTest;
private String tech;
private BigDecimal subjectTypeCode;
private String subjectId;
private String verified;
private Date dateSampleCollected;
private String sampleComment;
private Date dateSampleProcessed;
private Character animalIdType;
private String printed;
private String sampleComment2;
private Set cpResultses = new HashSet(0);

public CpSample() {
}


public CpSample(CpSampleId id) {
this.id = id;
}
public CpSample(CpSampleId id, String expTest, String tech, BigDecimal subjectTypeCode, String subjectId, String verified, Date dateSampleCollected, String sampleComment, Date dateSampleProcessed, Character animalIdType, String printed, String sampleComment2, Set cpResultses) {
this.id = id;
this.expTest = expTest;
this.tech = tech;
this.subjectTypeCode = subjectTypeCode;
this.subjectId = subjectId;
this.verified = verified;
this.dateSampleCollected = dateSampleCollected;
this.sampleComment = sampleComment;
this.dateSampleProcessed = dateSampleProcessed;
this.animalIdType = animalIdType;
this.printed = printed;
this.sampleComment2 = sampleComment2;
this.cpResultses = cpResultses;
}

public CpSampleId getId() {
return this.id;
}

public void setId(CpSampleId id) {
this.id = id;
}
public String getExpTest() {
return this.expTest;
}

public void setExpTest(String expTest) {
this.expTest = expTest;
}
public String getTech() {
return this.tech;
}

public void setTech(String tech) {
this.tech = tech;
}
public BigDecimal getSubjectTypeCode() {
return this.subjectTypeCode;
}

public void setSubjectTypeCode(BigDecimal subjectTypeCode) {
this.subjectTypeCode = subjectTypeCode;
}
public String getSubjectId() {
return this.subjectId;
}

public void setSubjectId(String subjectId) {
this.subjectId = subjectId;
}
public String getVerified() {
return this.verified;
}

public void setVerified(String verified) {
this.verified = verified;
}
public Date getDateSampleCollected() {
return this.dateSampleCollected;
}

public void setDateSampleCollected(Date dateSampleCollected) {
this.dateSampleCollected = dateSampleCollected;
}
public String getSampleComment() {
return this.sampleComment;
}

public void setSampleComment(String sampleComment) {
this.sampleComment = sampleComment;
}
public Date getDateSampleProcessed() {
return this.dateSampleProcessed;
}

public void setDateSampleProcessed(Date dateSampleProcessed) {
this.dateSampleProcessed = dateSampleProcessed;
}
public Character getAnimalIdType() {
return this.animalIdType;
}

public void setAnimalIdType(Character animalIdType) {
this.animalIdType = animalIdType;
}
public String getPrinted() {
return this.printed;
}

public void setPrinted(String printed) {
this.printed = printed;
}
public String getSampleComment2() {
return this.sampleComment2;
}

public void setSampleComment2(String sampleComment2) {
this.sampleComment2 = sampleComment2;
}
public Set getCpResultses() {
return this.cpResultses;
}

public void setCpResultses(Set cpResultses) {
this.cpResultses = cpResultses;
}
}


Here is the code I'm using for my insert:

public void create(CpSample sample)
throws AdException {

try {
begin();
getSession().save(sample);
getSession().flush();
getSession().evict(sample);
commit();
} catch( HibernateException e ) {
rollback();
System.out.println(e);
throw new AdException("Could not create testType " + sample.getSubjectId(),e);
}
}

My dates going into my create function look like this "Fri Jun 19 09:51:49 CDT 2009" but once they get inserted into the database the time portion gets drop, so all that get inserted into the database is 6/19/2009.

Im kind of new to Hibernate, so thats the reason I let the Netbeans IDE generate the XML and class files.

Any help or suggestions would be appreciated. Thanks.


Top
 Profile  
 
 Post subject: Re: Problem inserting dates/times.
PostPosted: Fri Jun 19, 2009 11:18 am 
Newbie

Joined: Wed May 27, 2009 11:43 am
Posts: 4
i found that using timestamp instead of date works from a previous posting. Thanks.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.