Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Beans > Re: Struts/Hibe...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 5 Topic 1339 of 1403
Post > Topic >>

Re: Struts/Hibernate and date troubles

by fthomas <thomas.fazekas@[EMAIL PROTECTED] > Feb 18, 2008 at 01:11 AM

On Feb 17, 5:38 pm, Donkey Hot <s...@[EMAIL PROTECTED]
> wrote:
> fthomas <thomas.faze...@[EMAIL PROTECTED]
> wrote in
news:e01e47a3-23bc-4911-8bcc-
> 2c7b1f873...@[EMAIL PROTECTED]
>
>
>
> > Dear all,
>
> > I'm getting squeezed between Struts and Hibernate when I use Date type
> > for a record.
> > My setup is the simplest possible.
> > This is my mappings file
> ><?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">
>
> ><hibernate-mapping>
> >  <class name="com.ft.ht.DictatorForm" table="DICTATOR">
>
> >     <meta attribute="class-description">
> >       testing Struts with Hibernate
> >     </meta>
>
> >     <id name="id" type="int" column="DICTATOR_ID">
> >       <meta attribute="scope-set">protected</meta>
> >       <generator class="native"/>
> >     </id>
>
> >     <property name="added" column="ADDED" type="timestamp"/>
> >     <property name="firstName" type="java.lang.String" not-null="true"
> > column="FIRST_NAME"/>
> >     <property name="lastName" type="java.lang.String" not-null="true"
> > column="LAST_NAME"/>
> >     <property name="birthDate" column="BIRTH_DATE" type="timestamp"/>
> >     <property name="offsprings" type="short" column="OFFSPRINGS"/>
>
> >  </class>
> ></hibernate-mapping>
>
> > The timestamp type gets translated into java.util.Data in the POJO and
> > in datetime in the
> > database schema. I heve MySQL as my DB.
>
> > I use the above mapping to generate a POJO which then I modify to
> > extend ActionForm.
> > I have to modify then all the setters to accept String (instead of
> > java.util.Date), that's to make
> > Struts happy.
>
> > The trouble is that Hibernate is unhappy with the setter. When I try
> > to commit something with Date I get :
>
> > org.hibernate.PropertyAcces***ception: IllegalArgumentException
> > occurred while calling setter of com.ft.ht.DictatorForm.birthDate
>
> > If the setters are let to accept Date then Strings shouts at me...
>
> > So far I was experimenting only with Strings and Dates. If I go only
> > with String everything is working...
>
> > What am I to do then? Can somebody point me to a complete example
> > which uses Hibernate with Struts and
> > commits multiple types of data to the Database (MySQL)
>
> > Cheers,
> > Thomas
>
> I have  not a master's degree on Hibernate, but what strikes to my eye
is
> that you declare type="java.lang.String" to strings and type="timestamp"
to
> dates. If java.lang.String is correct, then maybe date-columns want a
java-
> classdef too, no?
>
> Dunno if it has to be java.util.Date or java.sql.Date or
> java.sql.Timestamp...

Thanks the tip but unfortunately it doesn't help.
The basic problem still remains, namely Struts and Hibernate require
different types for the accessor methods.
After some thinking I've came to realize that my approach might be
wrong,
I shouldn't use the same class for the Struts ActionForm and for the
Hibernate persistence objects. It might work for simple cl***** where
all
the members are Strings but this is not the way to go for other types.

I'm not sure though, so I would really appreciate if somebody
with experience with both Hibernate and Struts would weigh in on this.

Thanks,
Thomas
 




 5 Posts in Topic:
Struts/Hibernate and date troubles
fthomas <thomas.fazeka  2008-02-17 05:31:12 
Re: Struts/Hibernate and date troubles
Donkey Hot <spam@[EMAI  2008-02-17 16:38:20 
Re: Struts/Hibernate and date troubles
fthomas <thomas.fazeka  2008-02-18 01:11:33 
Re: Struts/Hibernate and date troubles
Deepak Srivastava <dee  2008-02-27 08:44:17 
Re: Struts/Hibernate and date troubles
Deepak Srivastava <dee  2008-02-27 08:46:31 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Thu Dec 4 0:41:08 CST 2008.