Hi all,

I am having some problems creating a simple crud with tapestry-hibernate
5.0.14.   I followed the documentation and I have it mostly working.  I can
edit and save an existing entity with the @Persist("entity") annotation but
if I try to create a new entity by setting the value to a newly instantiated
entity I get this error:

# org.apache.tapestry5.runtime.ComponentEventException
Error persisting field PersistEntity:button: Failed persisting an entity in
the session. Only entities attached to a Hibernate Session can be persisted.
entity: [EMAIL PROTECTED]

context
eventType
    setToTransient

# org.hibernate.TransientObjectException
object references an unsaved transient instance - save the transient
instance before flushing: com.roialte.entities.Button

I figured I was doing something wrong so I copied the PersistEntity.tml and
PersistEntity.java into my project from the tapestry-hibernate project. 
loaded the page and clicked the "set to transient" link and I got the same
error.  

I am at a loss here as i cannot figure out what I'm doing wrong.   How do u
create a new entity for use within an edit page when using the
@Persist('entity') annotation?  I am using tapestry versions 5.0.14 and
mysql 5.0 for my db.  Any help is greatly appreciated. 

Thanks!


here is a quick peek at my converted version of code from the
tapesty-hibernate project:

java:
public class PersistEntity
{
    @Persist("entity")
    @Property
    private Button button;

    @Inject
    private ButtonDAO ButtonDAO;

    @Inject
    private Session session;

    @Inject
    private HibernateSessionManager manager;

    void onCreateEntity()
    {
        Button button = new Button();
        button.setName("name");

        ButtonDAO.save(button);

        this.button = button;
    }

    void onChangeName()
    {
        button.setName("name2");

        // No commit, so no real change.
    }

    void onSetToTransient()
    {
        button = new Button();
    }

    void onSetToNull()
    {
        button = null;
    }

    void onDelete()
    {
        List<Button> buttons = ButtonDAO.findAll();

        ButtonDAO.delete(buttons.toArray(new Button[0]));
    }
}


@Entity
@Table(name = "button", catalog = "test", uniqueConstraints = {})
public class Button {

        private Integer id;
        private String name;
                
    
        @Id 
        @GeneratedValue(strategy=GenerationType.AUTO)
        @Column(name = "id", unique = true, nullable = false, insertable = true,
updatable = true)    
        public Integer getId() {
                return id;
        }

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


        @Column(name = "name", unique = false, nullable = false, insertable = 
true,
updatable = true, length=128)
        @Validate("required,maxlength=128")
        public String getName() {
                return name;
        }

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

tml:
<html xmlns:t="http://tapestry.apache.org/schema/tapestry_5_0_0.xsd";>
<body>
        <p>entity name: <t:if test="button">${button.name}</t:if></p>
        <p><t:eventlink event="createEntity">create entity</t:eventlink></p>
        <p><t:eventlink event="changeName">change the name</t:eventlink></p>
        <p><t:eventlink event="setToNull">set to null</t:eventlink></p>
        <p><t:eventlink event="delete">delete</t:eventlink></p>
        <p><t:eventlink event="setToTransient">set to 
transient</t:eventlink></p>
</body>
</html>




-- 
View this message in context: 
http://www.nabble.com/T5%3A-tapestry-hibernate-problem-when-setting-%40Persist%28%22entity%22%29-to-a-transient-object-tp18996169p18996169.html
Sent from the Tapestry - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to