-->
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.  [ 8 posts ] 
Author Message
 Post subject: Problems with timestamp and Postgres
PostPosted: Tue May 11, 2004 8:45 am 
Beginner
Beginner

Joined: Tue May 11, 2004 8:24 am
Posts: 23
Hi,

I have a serious problem with PostgreSQL and Timestamps mapping to a java.util.Date.
I get a StringArrayOutOfBoundsException.
This is the physical content of the field: 2004-05-11 09:47:31.869

Here is a trace:

java.lang.StringIndexOutOfBoundsException: String index out of range: 23
at java.lang.String.charAt(String.java:444)
at org.postgresql.jdbc2.ResultSet.toTimestamp(Unknown Source)
at org.postgresql.jdbc2.ResultSet.getTimestamp(Unknown Source)
at org.postgresql.jdbc2.ResultSet.getTimestamp(Unknown Source)
at com.mchange.v2.c3p0.impl.C3P0ResultSet.getTimestamp(C3P0ResultSet.java:363)
at net.sf.hibernate.type.TimestampType.get(TimestampType.java:22)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
at net.sf.hibernate.type.AbstractType.hydrate(AbstractType.java:66)
at net.sf.hibernate.loader.Loader.hydrate(Loader.java:611)
at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:552)
at net.sf.hibernate.loader.Loader.instanceNotYetLoaded(Loader.java:511)
at net.sf.hibernate.loader.Loader.getRow(Loader.java:426)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:209)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:834)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1536)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at de.webjazz.pleasure.backend.persist.PersistHelper.executeNamedQuery(PersistHelper.java:100)

I first thought about a Driver problem, so downloaded the most recent drivers.

This on Mac OS X 10.3
using PostgreSQL 7.4
JDK 1.4.2

Any ideas on this?

Regards,

Alex


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 5:10 am 
Regular
Regular

Joined: Wed May 12, 2004 3:03 am
Posts: 51
Location: France
Hi,

Could you give the mapping files and Java code please...


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 7:04 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Find old jar in classpath this is a driver problem, I think driver for 7.1 fails with this message if you use timestamp in 7.2 or some more new version of server.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 7:27 am 
Beginner
Beginner

Joined: Tue May 11, 2004 8:24 am
Posts: 23
Hi,

this is my mapping:

<class name="PersistUser" table="users2" optimistic-lock="version" >
<id name="ID"><generator class="uuid.hex" /></id>
<version name="version" type="long" />
<property name="loginName" length="200" not-null="true"/>
<property name="password" length="120" not-null="true" />
<property name="email1" length="200" not-null="true" />
<property name="email2" length="200" />
<property name="email3" length="200"/>
<property name="fullName" length="250"/>
<property name="admin" type="boolean" />
<property name="online" type="boolean"/>
</class>

<class name="PersistMessage" table="message2" optimistic-lock="version">
<id name="ID"><generator class="uuid.hex"/></id>
<version name="version" type="long"/>
<property name="subject" length="200" not-null="true"/>
<property name="read" type="boolean"/>
<property name="attachment" type="text"/>
<property name="body" type="text"/>
<property name="date" type="timestamp"/>
<many-to-one name="fromUser" column="from_user_id" class="PersistUser" />
<many-to-one name="toUser" column="to_user_id" class="PersistUser" />
</class>

Usage:

public class PersistMessage extends AbstractBasicPersistObject {

private String subject = null;
private String attachment = null;
private String body = null;
private Date date = null;
private PersistUser fromUser = null;
private PersistUser toUser = null;
private boolean read = false;

... getters & setters

class PersistHelper

public List getAll(Class o) {
Vector out = new Vector();
try {
Session session = _factory.openSession();
List l = session.find("from " + o.getName());
if(l != null) out.addAll(l);
session.close();
} catch (HibernateException exc) {
_log.fatal(exc.getMessage());
exc.printStackTrace();
provideGUIFeedback(exc);
}
return out;
}

Somewhere else:

helper.getAll(PersistMessage.class);

I believe this is a JDBC Driver related problem. I found some threads with similar problems in other forums, always point to Driver version problems.
I upgraded to PostgreSQL 7.4.2 this morning, used the latest "jdbc.jar".
The Problem still exists.

Strange thing: When I do this:

List drivers = Collections.list(DriverManager.getDrivers());
for (int i = 0; i < drivers.size(); i++) {
Driver driver = (Driver) drivers.get(i);
String name = driver.getClass().getName();
int majorVersion = driver.getMajorVersion();
int minorVersion = driver.getMinorVersion();
_log.info("Available JDBC-Driver: " + name + " (" + majorVersion + "." + minorVersion + ")");
}

It says I am using: org.postgresql.Driver (7.2)
???
Is the Driver having a different version cycle?

Is there a way to force hibernate to use specific jar?

I already searched through all my classpath, but could not find any older postgres-jdbc jar.

Any hint is very much apprechiated.

Regards,

Alex


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 7:44 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
you can download driver from http://jdbc.postgresql.org, but must be no
problems with driver from server distribution too.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 7:58 am 
Regular
Regular

Joined: Wed May 12, 2004 3:03 am
Posts: 51
Location: France
Maybe you could try not to write explicitly the type of the attribute date in the hbm.xml file.

Or, try the type date...

I don't find something else... sorry...

Tell me if you find.

Charles


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 8:23 am 
Beginner
Beginner

Joined: Tue May 11, 2004 8:24 am
Posts: 23
Hi,

I found the problem. It was an old Driver, some old Software might have installed.

Thanks for your thoughts.

This brings one more general question to me again:

What happens if you have more than one Driver in your classpath? Is there a way force Java to use this exact version?

I believe this a more general Java problem.

Regards,

Alex


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 12, 2004 9:08 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
Yes, this is general JAVA problem, you can not have two class or more class versions in the same classloader.
BTW It is solved many years ago in COM to stop DLL hell in windows.


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