-->
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.  [ 9 posts ] 
Author Message
 Post subject: Major problems migrating to 3.1.x from 3.0
PostPosted: Thu Feb 02, 2006 6:37 am 
Newbie

Joined: Thu Feb 02, 2006 4:17 am
Posts: 6
Location: Planet Earth
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version: 3.1.x

Mapping documents:

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

Full stack trace of any exception that occurs:
1.java.lang.ClassCastException: java.lang.String
at org.hibernate.type.TimestampType.toString(TimestampType.java:55)

2.
org.hibernate.PropertyAccessException: IllegalArgumentException occurred calling getter of com.pa.asset.orm.base.BaseAgent.UserName
at org.hibernate.property.BasicPropertyAccessor$BasicGetter.get(BasicPropertyAccessor.java:171)
at org.hibernate.tuple.AbstractEntityTuplizer.getIdentifier(AbstractEntityTuplizer.java:176)
at org.hibernate.persister.entity.AbstractEntityPersister.getIdentifier(AbstractEntityPersister.java:3257)
at org.hibernate.persister.entity.AbstractEntityPersister.isTransient(AbstractEntityPersister.java:2983)
at org.hibernate.engine.ForeignKeys.isTransient(ForeignKeys.java:181)
The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:



I am facing these issues migrating from 3.0 to 3.1.x for any operation (selects or update) .Most of these are simple select operations and work fine in 3.0 .
The first execption occurs always ,presumably beacuse most of the hiberanate mapping files have a date / timestamp field .
The second exception occurs possibly beacuse the primary key in the table is a character filed and not a numeric field..
These exceptions

I have been using hibernate synchronizer (an eclipse plugin ) to generate these mapping files ..When will i be able to use hibernate 3.1 afterall


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 5:33 pm 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
Can you post your HBM.xml for class "com.pa.asset.orm.base.BaseAgent" ?

Can you post your table description for the table, in mysql "DESCRIBE myTable" ?

Can you post the POJO or at least the getter/setters, constructor, field variables ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 2:53 am 
Newbie

Joined: Thu Feb 02, 2006 4:17 am
Posts: 6
Location: Planet Earth
dlmiles wrote:
Can you post your HBM.xml for class "com.pa.asset.orm.base.BaseAgent" ?


<class
name="Agent"
table="Agent" >
<id
name="UserName"
type="string"
column="UserName">

<generator class="assigned"/>
</id>


<property
name="FullName"
column="FullName"
type="string"
not-null="false"
length="50"
/>

<property
name="Created"
column="Created"
type="timestamp"
not-null="false"
length="23"
/>

<property
name="Grace"
column="Grace"
type="integer"
not-null="false"
length="10"
/>



<set name="MemberOfGroups" inverse="true">
<key column="UserName"/>
<one-to-many class="MemberOfGroup" />
</set>

<many-to-one
name="Person"
column="Person_ID"
class="Person"
not-null="false">

</many-to-one>


</class>

dlmiles wrote:
Can you post your table description for the table, in mysql "DESCRIBE myTable" ?

CREATE TABLE Agent (
UserName NVARCHAR(10) NOT NULL,
FullName NVARCHAR(50),
Expires DATETIME,
Person_ID INTEGER,
Grace INTEGER,
Created DATETIME
)
Go

CREATE INDEX PK_Agent ON Agent (UserName ASC)
Go

ALTER TABLE Agent ADD CONSTRAINT PK_Agent PRIMARY KEY (UserName)
Go

ALTER TABLE Agent ADD CONSTRAINT FK_Agent_PERSON FOREIGN KEY (Person_ID)
REFERENCES PERSON (ID)
ON DELETE RESTRICT
ON UPDATE RESTRICT
Go


dlmiles wrote:
Can you post the POJO or at least the getter/setters, constructor, field variables ?


// primary key
private java.lang.String userName;

// fields
private java.lang.String fullName;
private java.util.Date expires;
private java.lang.Integer grace;
private java.util.Date created;

// many to one
private com.pa.asset.orm.Person person;

// collections
private java.util.Set<com.pa.asset.orm.MemberOfGroup> memberOfGroups;
private java.util.Set<com.pa.asset.orm.Person> agentPerson;

Here are some of the different type of fields used in this mapping
Agent class is inherited from the class BaseAgent..and I am using hibernate with Spring 1.2.6 ,tomcat 5.5 and SQL server 2000


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 4:46 am 
Regular
Regular

Joined: Tue Dec 14, 2004 5:21 am
Posts: 104
Location: india
there is not much work needed in migrating to version 3.1 .
http://www.hibernate.org/357.html
i think the PropertyAccesException is due to wrong type of value passed as id .

_________________
sHeRiN
thanks for your ratings ...... :)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 7:50 am 
Newbie

Joined: Thu Feb 02, 2006 4:17 am
Posts: 6
Location: Planet Earth
But this code works in hibernate 3.0 and its not just one place .I get these errors every where ...More over these are not update operations mere select operations ....I am wondering if there is any jar file that is causing this problem


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 10, 2006 4:19 pm 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
I use java.sqlTimestamp in my POJOs due to having problem using java.lang.Date, never had a problem since.

Given the error is related to a Timestamp hibernate type is it possible to try that avenue out ?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 2:27 am 
Newbie

Joined: Thu Feb 02, 2006 4:17 am
Posts: 6
Location: Planet Earth
I managed to find the cause for the bugs

First one related to the timestamp :
1. In my hibernate query I was doing a query something like
List list = getHibernateTemplate().find(" from table t where t.somedate = ?",args);

where args was defined as
Object[] args = {dateinstringform};

I should have been passing the parameter as an object of type Date()
like

Object[] args = {dateindateform};

I guess hibernate 3.0 automatically did the type conversion from String to Date ..
-------------------------------
2.An even more amazing reason for the second bug ..This one was a shocker....

My query was something like

List list = getHibernateTemplate().find("select grp from Person p,Group grp where p.type = grp.class and grp.Person = ?",args);

where args was defined as
Object[] args = {personinstringform};

It should have been

Object[] args = {new Person(personinstringform)};

But I guess since the primary key was in string form, Hibernate 3.0 automagically created a new type using the constructor Person(String name) ....

I wonder if these features were removed on purpose in hibernate 3.1 ... I feel it may be a good thing to have this type of automatic type conversion atleast in the first case...Would appreciate some kind of thoughts about this from the guys at hibernate too..How about some kind of polling
____________________________________________________
Quote:That which hits the fan tends to get flung in all directions.Get out of the way before u throw


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 4:24 am 
Regular
Regular

Joined: Sun May 08, 2005 2:48 am
Posts: 118
Location: United Kingdom
My 2 cents.

Object[] usualy means you have to be type specific if type matters; this is common to "the java way of using this language technique". Since 99% of all objects have a String representation I suppose its not possible to guess the type 100% if all you provide is a String.

Granted HQL can attempt to work out the datatype from the context, but aren't you asking it to do a lot for every execution of the statement and leaving the door open to easy programming errors that probably wont show up in normal testing. All that processing work would be unecessary when I think that for every situation the programmer already knows the type when he constructs the HQL.

My 2 cents.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 13, 2006 6:43 am 
Newbie

Joined: Thu Feb 02, 2006 4:17 am
Posts: 6
Location: Planet Earth
dlmiles wrote:

Object[] usualy means you have to be type specific if type matters; this is common to "the java way of using this language technique". Since 99% of all objects have a String representation I suppose its not possible to guess the type 100% if all you provide is a String.

But hibernate 3.0 did recognized it right ..I wonder why this stopped working in 3.1 ( and what such things have stopped working so I can trace where such operations have been performed)..

dlmiles wrote:
Granted HQL can attempt to work out the datatype from the context, but aren't you asking it to do a lot for every execution of the statement and leaving the door open to easy programming errors that probably wont show up in normal testing. All that processing work would be unecessary when I think that for every situation the programmer already knows the type when he constructs the HQL

Yes it can lead to lazy & error prone programming if used unwisely ..but it can be useful for simple operations like converting from String to a numeric type or date type..where in the type of data is usually validated in the front end or in the Struts layer

_________________
Quote:That which hits the fan tends to get flung in all directions.Get out of the way before u throw


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