-->
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.  [ 7 posts ] 
Author Message
 Post subject: simple saving Date() object not saving time
PostPosted: Wed Aug 11, 2004 10:36 am 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
Hibernate version:
2.1.5

Mapping documents:
<property name="lastModified" type="date"/>

Code between sessionFactory.openSession() and session.close():
standard

Full stack trace of any exception that occurs:
no stack trace

Name and version of the database you are using:
oracle 9i

Debug level Hibernate log excerpt:
no bugs

when i save an object with a java.util.Date() attribute, then check the database, the time is not being persisted.. its set to 12:00:00am.. i saw a similar post that said change the property type to timestamp.. tried this and got a horrible oracle error: ORA-03115: unsupported network datatype or representation

please advise.

G


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 11:06 am 
Beginner
Beginner

Joined: Thu Apr 29, 2004 4:03 pm
Posts: 40
hmm... what is the sql type of your date column?

think about using java.sql.Date


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 11:31 am 
Beginner
Beginner

Joined: Tue Jul 20, 2004 1:53 am
Posts: 43
Location: India
Instead of
Code:
<property name="lastModified" type="date"/>

try
Code:
<property name="lastModified" type="timestamp"/>

_________________
Thanks,
Binil Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 12:46 pm 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
"i saw a similar post that said change the property type to timestamp.. "

as i stated, i've tried that and got the horrible oracle error.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 2:15 pm 
Beginner
Beginner

Joined: Tue Jul 20, 2004 1:53 am
Posts: 43
Location: India
Hi,

I tried a standalone testcase and it worked for me in 8i.

The entity code is as follows :
Code:
import java.util.Date;

public class MyEntity
{
    private long id;
    private Date date;

    // ... getters and setters for these two properties
}


It is mapped as :
Code:
<?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 package="tavant.platform.persistence.hibernate.date">
    <class name="MyEntity" table="MY_ENTITY">
        <id name="id" column="MY_ID" type="long">
            <generator class="native"/>
        </id>

        <property name="date" column="MY_DATE" type="timestamp"/>
    </class>
</hibernate-mapping>


And I use a test to try out the mapping :
Code:
public class Test
{
    public static void main(String[] args) throws Exception
    {
        Session session = new Configuration()
            .addClass(MyEntity.class)
            .buildSessionFactory()
            .openSession();

        System.out.println("Openend Session");

        Transaction transaction = session.beginTransaction();

        System.out.println("Started Transaction");

        MyEntity e = new MyEntity();
        e.setDate(new Date());

        System.out.println("Created Transient Entity");

        session.save(e);

        transaction.commit();

        System.out.println("Persisted Entity");

        session.close();
    }
}


It works well, and inserts the entity correctly.
Code:
SQL> desc my_entity;
Name                                      Null?    Type
----------------------------------------- -------- ----------------------------

MY_ID                                     NOT NULL NUMBER(19)
MY_DATE                                            DATE

SQL> select my_id, to_char(my_date, 'DD/MM/YY HH24-MI-SS') from my_entity;

     MY_ID TO_CHAR(MY_DATE,'
---------- -----------------
        27 11/08/04 21-05-27


Try this simple code on 9i, and see if it works.

_________________
Thanks,
Binil Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 11, 2004 3:41 pm 
Beginner
Beginner

Joined: Tue Jul 20, 2004 1:53 am
Posts: 43
Location: India
I tried the testcase on 9i and it worked fine for me!

_________________
Thanks,
Binil Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 10:12 am 
Beginner
Beginner

Joined: Sun Jun 06, 2004 10:13 am
Posts: 20
interesting, i tried your test case and got the same problem, only difference is that i used

<generator class="uuid.hex"/> with a string in my class

for my id instead of native and long.

using oracle 9i with ojdbc14.jar drivers.

here's the horrible stack trace.. i think i've given up though, and will use a horrible hack as a work around (storing time as a long for milliseconds)

thanks for trying!


Openend Session
Started Transaction
Created Transient Entity
Aug 18, 2004 7:02:50 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 3115, SQLState: 63000
Aug 18, 2004 7:02:50 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-03115: unsupported network datatype or representation

Aug 18, 2004 7:02:50 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 3115, SQLState: 63000
Aug 18, 2004 7:02:50 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-03115: unsupported network datatype or representation

Aug 18, 2004 7:02:50 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 3115, SQLState: 63000
Aug 18, 2004 7:02:50 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-03115: unsupported network datatype or representation

Aug 18, 2004 7:02:50 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 3115, SQLState: 63000
Aug 18, 2004 7:02:50 AM net.sf.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: ORA-03115: unsupported network datatype or representation

Aug 18, 2004 7:02:50 AM net.sf.hibernate.JDBCException <init>
SEVERE: Could not execute JDBC batch update
java.sql.BatchUpdateException: ORA-03115: unsupported network datatype or representation

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4133)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at apacs.personnel.TestEntity.main(TestEntity.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Aug 18, 2004 7:02:50 AM net.sf.hibernate.impl.SessionImpl execute
SEVERE: Could not synchronize database state with session
net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at apacs.personnel.TestEntity.main(TestEntity.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Caused by: java.sql.BatchUpdateException: ORA-03115: unsupported network datatype or representation

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4133)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
... 10 more
Exception in thread "main" net.sf.hibernate.JDBCException: Could not execute JDBC batch update
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:129)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2417)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2367)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2236)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:61)
at apacs.personnel.TestEntity.main(TestEntity.java:38)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:78)
Caused by: java.sql.BatchUpdateException: ORA-03115: unsupported network datatype or representation

at oracle.jdbc.dbaccess.DBError.throwBatchUpdateException(DBError.java:459)
at oracle.jdbc.driver.OraclePreparedStatement.executeBatch(OraclePreparedStatement.java:4133)
at net.sf.hibernate.impl.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:54)
at net.sf.hibernate.impl.BatcherImpl.executeBatch(BatcherImpl.java:122)
... 10 more

Process finished with exit code 1


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