-->
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.  [ 3 posts ] 
Author Message
 Post subject: makePersistent is not working but findById is working
PostPosted: Wed Apr 28, 2010 7:18 pm 
Newbie

Joined: Wed Apr 28, 2010 7:14 pm
Posts: 3
makePersistent is not working but findById is working. What's wrong?

Code:
        <%!
            ItemDao itDao = new ItemDao();
            Item it = new Item();
        %>
        <%
            it.setBonusataque(1);
            it.setBonusdefesa(1);
            it.setNome("Staff of Shaman");

            itDao.makePersistent(it);
            itDao.flush();
         %>


Code:
package Model;

import java.io.Serializable;
import javax.persistence.*;

@SequenceGenerator(name="seqItem",sequenceName="item_id_seq",initialValue=1)
@Table(name = "item")
@Entity
public class Item implements Serializable
{
    @Id
    @GeneratedValue(generator="seqItem", strategy=GenerationType.AUTO)
    @Column(name="id")
    private int id;

    @Column(name="bonusataque", nullable=true, length=4)
    private int bonusataque;

    @Column(name="bonusdefesa", nullable=true, length=4)
    private int bonusdefesa;

    @Column(name="nome", nullable=true, length=200)
    private String nome;
   
    ...


Top
 Profile  
 
 Post subject: Re: makePersistent is not working but findById is working
PostPosted: Wed Apr 28, 2010 7:23 pm 
Newbie

Joined: Wed Apr 28, 2010 7:14 pm
Posts: 3
There is no exception, it just doesn't work

SQL output

Code:
INFO: Hibernate:
    select
        nextval ('item_id_seq')
INFO: Hibernate:
    insert
    into
        item
        (bonusataque, bonusdefesa, nome, id)
    values
        (?, ?, ?, ?)


entity on run-time is filled in with the correct values


Top
 Profile  
 
 Post subject: Re: makePersistent is not working but findById is working
PostPosted: Wed Apr 28, 2010 10:28 pm 
Newbie

Joined: Wed Apr 28, 2010 7:14 pm
Posts: 3
SOLVED

Code:
    public T makePersistent(T entity) throws Exception {
        try {
            getSession().saveOrUpdate(entity);
            getSession().getTransaction().begin();
            getSession().getTransaction().commit();
            return entity;
        } catch (HibernateException e) {
            getSession().getTransaction().rollback();
            throw new Exception(e.getMessage());
        }
    }


Crappy hibernate doesn't commit


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