Hello Team, I am new in JPA and facing some problem in entity relationship. Could you please help:
JPA 'OneToMany/ManyToOne' relationship is not detected by OpenJPA at the time of persistence, if no DataBase level constraint defined. Consider the two tables, User and UserApp, do not have backend database relationship (primary key - Foreign key) instead having JPA relationship. Below are the following two entities: public class User implements Serializable { private static final long serialVersionUID = 1L; @Id private String id; //bi-directional many-to-one association to kna1 @OneToMany( mappedBy="userBean") private Set<UserApp> userApps; public Set<UserApp> getUserAppss() { return this.userApps; } public void setUserApps(Set<UserApp> userApps) { this.userApps = userApps; } .. .. .. @Table(name="USER_APP", schema="RDACCESS") public class UserApp implements Serializable { private static final long serialVersionUID = 1L; @EmbeddedId private UserAppPK id; @Temporal( TemporalType.DATE) private Date lastlogin; // bi-directional many-to-one association to User @ManyToOne( optional=false ) @JoinColumns({ @JoinColumn(name = "ID", referencedColumnName = "ID")}) private User userBean; public User getUserBean() { return this.userBean; } public void setUserBean(User userBean) { this.userBean = userBean; } .. .. .. @Embeddable public class UserAppPK implements Serializable { //default serial version id, required for serializable classes. private static final long serialVersionUID = 1L; private String id; private String appname; public UserAppPK() { } public String getId() { return this.id; } public void setId(String id) { this.id = id; } public String getAppname() { return this.appname; } public void setAppname(String appname) { this.appname = appname; } ... ... ... You can check, these two tables are linked with field "ID". The problem is, Application is allowing to insert UserApp without User's "ID" . Code which inserts value in UserApp: UserApp userApp ; UserAppPK id; UserAppManager uAppMgr=new UserAppManager(JpaManager.getCurrentSession() userApp.setLastlogin(convertedDate); id.setAppname(p_appName); id.setId(p_LoginUser); userApp.setId(id); uAppMgr.createUserApp(userApp); .. .. .. @Action(Action.ACTION_TYPE.CREATE) public String createUserApp(UserApp userApp) throws Exception { EntityManager em = getEntityManager(); try { em.getTransaction().begin(); em.persist(userApp); em.getTransaction().commit(); .. .. .. I may be missing some configuration or the way of implementation. Could you please help me? -- View this message in context: http://openjpa.208410.n2.nabble.com/JPA-OneToMany-ManyToOne-relationship-is-not-detected-by-OpenJPA-at-the-time-of-persistence-if-no-Dat-tp7580870.html Sent from the OpenJPA Users mailing list archive at Nabble.com.