Please help ! Can't persist data into related tables
valsart Feb 6, 2008 8:52 AMHello !
I'm trying to persist some data into related tables for more then a week, but it's not working at all..
Please Help !
This is the code...
package com.st.st; // Generated 06.02.2008 1:13:21 by Hibernate Tools 3.2.0.b10 import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import static javax.persistence.GenerationType.IDENTITY; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import org.hibernate.validator.NotNull; /** * Info generated by hbm2java */ @Entity @Table(name = "info", catalog = "seamtest") @Name("info") public class Info implements java.io.Serializable { private Integer infoId; private User user; private int infoFullPayment; public Info() { } public Info(User user, int infoFullPayment) { this.user = user; this.infoFullPayment = infoFullPayment; } @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "info_id", unique = true, nullable = false) public Integer getInfoId() { return this.infoId; } public void setInfoId(Integer infoId) { this.infoId = infoId; } @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id", nullable = false) @NotNull public User getUser() { return this.user; } public void setUser(User user) { this.user = user; } @Column(name = "info_full_payment", nullable = false) @NotNull public int getInfoFullPayment() { return this.infoFullPayment; } public void setInfoFullPayment(int infoFullPayment) { this.infoFullPayment = infoFullPayment; } }
package com.st.st; // Generated 06.02.2008 1:13:21 by Hibernate Tools 3.2.0.b10 import java.util.HashSet; import java.util.Set; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import static javax.persistence.GenerationType.IDENTITY; import javax.persistence.Id; import javax.persistence.OneToMany; import javax.persistence.Table; import org.hibernate.validator.NotNull; /** * User generated by hbm2java */ @Entity @Table(name = "user", catalog = "seamtest") @Name("user") public class User implements java.io.Serializable { private Integer userId; private int userPayment; private Set<Info> infos = new HashSet<Info>(0); public User() { } public User(int userPayment) { this.userPayment = userPayment; } public User(int userPayment, Set<Info> infos) { this.userPayment = userPayment; this.infos = infos; } @Id @GeneratedValue(strategy = IDENTITY) @Column(name = "user_id", unique = true, nullable = false) public Integer getUserId() { return this.userId; } public void setUserId(Integer userId) { this.userId = userId; } @Column(name = "user_payment", nullable = false) @NotNull public int getUserPayment() { return this.userPayment; } public void setUserPayment(int userPayment) { this.userPayment = userPayment; } @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "user") public Set<Info> getInfos() { return this.infos; } public void setInfos(Set<Info> infos) { this.infos = infos; } }
package com.st.st; import javax.ejb.Stateless; import javax.persistence.EntityManager; import javax.persistence.PersistenceContext; import org.jboss.seam.annotations.In; import org.jboss.seam.annotations.Name; import com.st.st.insert; @Name("insert") public @Stateless class insertBean implements insert { @In private User user; @In private Info info; @PersistenceContext private EntityManager em; public void insert(Integer userPayment, Integer infoFullPayment){ Info info = new Info(); info.setInfoFullPayment(infoFullPayment); User user = new User(); userPayment = infoFullPayment*2; user.setUserPayment(userPayment); info.setUser(user); em.persist(info); } }
package com.st.st; import javax.ejb.Local; @Local public interface insert { public void insert(Integer userPayment, Integer infoFullPayment); }
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:s="http://jboss.com/products/seam/taglib" xmlns:ui="http://java.sun.com/jsf/facelets" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html" xmlns:a="http://richfaces.org/a4j" xmlns:rich="http://richfaces.org/rich" template="layout/template.xhtml"> <ui:define name="body"> <h:form> <h:inputText value="#{info.infoFullPayment}"/> <h:commandButton value="push" action="#{insert.insert}"/> </h:form> </ui:define> </ui:composition>