-->
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.  [ 5 posts ] 
Author Message
 Post subject: Why lifecycle interface can't work property?
PostPosted: Sun Feb 27, 2005 2:02 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Read the rules before posting!
http://www.hibernate.org/ForumMailingli ... AskForHelp

2.1.6

<class name="Topic" table="pagertest">
<id
column="ID"
name="id"
type="integer"
>
<generator class="native" />
</id>
<property
column="TIME"
length="19"
name="time"
not-null="false"
type="timestamp"
/>
<property
column="TITLE"
length="100"
name="title"
not-null="false"
type="string"
/>
<property
column="NAME"
length="20"
name="name"
not-null="false"
type="string"
/>
</class>
////////////////////////////////////////////////////////////////////////
<class name="Author" table="author">
<id
column="AUTHORID"
name="authorid"
type="string"
>
<generator class="native" />
</id>
<property
column="AGE"
length="11"
name="age"
not-null="false"
type="integer"
/>
<property
column="NAME"
length="100"
name="name"
not-null="false"
type="string"
/>
<property
column="EMAIL"
length="150"
name="email"
not-null="false"
type="string"
/>
</class>

:


Session s=HibernateUtil.currentSession();
Transaction tx=s.beginTransaction();
Topic t=new Topic();
t.setName("Yashnoo");
t.setTitle("Hi all !1");
Object id=s.save(t);
log.info("Get id: "+id);
tx.commit();
HibernateUtil.closeSession();


NOne:

MySQL 4.0.1:

13:32:17,004 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
Hibernate: insert into pagertest (TIME, TITLE, NAME) values (?, ?, ?)
13:32:17,284 INFO Test:35 - Get id: 104


INFO


Hi everyone:

I want to save an Author after save an Topic object.So I implements Lifecycle interface. But it seem don't work property. After save Topic,the author don't be saved :(
My topic javabean is:

Code:
public class Topic implements Serializable,Lifecycle {
   
    private static final Log log=LogFactory.getLog(Topic.class);

    /** identifier field */
    private Integer id;

    /** nullable persistent field */
    private Date time;

    /** nullable persistent field */
    private String title;

    /** nullable persistent field */
    private String name;

    /** full constructor */
    public Topic(Date time, String title, String name) {
        this.time = time;
        this.title = title;
        this.name = name;
    }

    /** default constructor */
    public Topic() {
    }

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

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getTime() {
        return this.time;
    }

    public void setTime(Date time) {
        this.time = time;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getName() {
        return this.name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String toString() {
        return new ToStringBuilder(this)
            .append("id", getId())
            .toString();
    }

    /* (non-Javadoc)
     * @see net.sf.hibernate.Lifecycle#onSave(net.sf.hibernate.Session)
     */
    public boolean onSave(Session s) throws CallbackException {
        Author au=new Author();
        au.setAge(22);
        au.setEmail("lyo@hibernate.com.cn");
        au.setName("LIren wang");
        Transaction tx=null;
        try {
            tx=s.beginTransaction();
            Object id=s.save(au);
            log.info("Saving  author ::: "+id);
            tx.commit();
        } catch (HibernateException e) {
           
        }
       
        return false;
    }

    /* (non-Javadoc)
     * @see net.sf.hibernate.Lifecycle#onUpdate(net.sf.hibernate.Session)
     */
    public boolean onUpdate(Session arg0) throws CallbackException {
        // TODO Auto-generated method stub
        return false;
    }

    /* (non-Javadoc)
     * @see net.sf.hibernate.Lifecycle#onDelete(net.sf.hibernate.Session)
     */
    public boolean onDelete(Session arg0) throws CallbackException {
        // TODO Auto-generated method stub
        return false;
    }

    /* (non-Javadoc)
     * @see net.sf.hibernate.Lifecycle#onLoad(net.sf.hibernate.Session, java.io.Serializable)
     */
    public void onLoad(Session arg0, Serializable arg1) {
        // TODO Auto-generated method stub
       
    }

}

I implements the "onSave" method.But the author don't be saved.why? How to use the Lifecycle interface to do this? Help!

_________________
You are not alone...


Top
 Profile  
 
 Post subject: :(
PostPosted: Mon Feb 28, 2005 6:02 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Any idea?

_________________
You are not alone...


Top
 Profile  
 
 Post subject: :(
PostPosted: Mon Feb 28, 2005 7:58 pm 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
Not anyone used it ? up

_________________
You are not alone...


Top
 Profile  
 
 Post subject: :(
PostPosted: Thu Mar 03, 2005 2:10 am 
Senior
Senior

Joined: Wed Dec 17, 2003 4:24 am
Posts: 188
up !

_________________
You are not alone...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 03, 2005 5:35 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Stop that bumping! If nobody answers your post, that might have a reason (not clear, nobody has time, nobody is interested in your particular problem). Wrecking other peoples nerves by pushing the thread up all the time won't motivate people any way to help you.


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