[jboss-user] [EJB3] - EJB & PostgreSQL FK?

Dirk Robbes do-not-reply at jboss.com
Sun Jul 1 09:40:33 EDT 2012


Dirk Robbes [https://community.jboss.org/people/underflyer] created the discussion

"EJB & PostgreSQL FK?"

To view the discussion, visit: https://community.jboss.org/message/745268#745268

--------------------------------------------------------------
Hi everyone,

im trying to deploy my EJB.jar on my new JBOSS 7.1.1. Well the deploy of the EJB-Container works like a charm. All Tables have been created, correctly. But I am unable to insert any Data in any Table where @ManyToOne Annotations are declared.
Example: Unidirectional ManyToOne

public class A
{
  private Integer id;
  @Id
  @GeneratedValue(stretegy=Generation.TYPE=Auto)
  public Integer getId(){ return id;}
  public void setId(Integer id){ this.id=id;}
}
 
public class B
{
  private Integer id;
  @Id
  @GeneratedValue(stretegy=Generation.TYPE=Auto)
  public Integer getId(){ return id;}
  public void setId(Integer id){ this.id=id;}
 
  private A a;
  @ManyToOne
  @JoinColumn(name="a_id", nullable=false)
  public A getA() {return a;}
  public void setA(A a){ this.a=a;}
}
 
 

this code, creates in PostgresSQL two Tables with (a, b)  with the corresponding Columns (a = id) (b = id, a_id)
Additional there are "two" (not one) ForeignKey Constraints defined, in Table "b":
- fk.... foreign key (a_id) references a (id)
- fk.... foreign key (id) references a(id)

the second FK-Constraint makes trouble:
INSERT A (id=1)  = OK!
INSERT B (id=1, a_id=1) = OK!
INSERT B (id=2, a_id=1) = ERROR !!!!!!

DETAIL key (id) = 2 is not present in table "a"


where is my fault? 
Thanks for Advice
--------------------------------------------------------------

Reply to this message by going to Community
[https://community.jboss.org/message/745268#745268]

Start a new discussion in EJB3 at Community
[https://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2029]

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20120701/4ebbca20/attachment.html 


More information about the jboss-user mailing list