[EJB 3.0] - Re: Unknown error
by fhh
Well, either it is a primary key then the constraint is that its unique and not null. Or it is a foreign key so that it is either null or refers to a row in the related table.
What is Hibernate supposed to do, if you set the user details to null? Then you would also assign null to the primary key which is not allowed.
Second problem: If you assign a new user details bean to the user bean you would also change the pk of the user bean that doesn't make sense.
So I doubt this would have ever worked. Simply try the @PrimaryKeyJoinColumn. In theory it should do exactly what you want to do.
Try this:
| @Entity
| @Table(name="usuario")
| public class UsuarioEJB {
|
| private Integer id;
| private UsuarioDetallesEJB usuarioDetallesEJB ;
|
| @Id
| @Column(name="idUsuario")
| public Integer getId() {
|
| return this.id;
|
| }
|
| // setter
|
| @OneToOne
| @PrimaryKeyJoinColumn
| public UsuarioDetallesEJB getUsuarioDetallesEJB() {
|
| return this.id;
|
| }
|
| //setter
|
| }
|
Regards
Felix
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4042619#4042619
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4042619
17 years, 4 months
[Persistence,JBoss/CMP, Hibernate, Database] - Fetch
by KoniKoni
How can i make a fetch of collections for follow case:
A(ManyToOne * ) -> (OneToMany 1 ) B (OneToMany 1)-> C (ManyToOne * ) C
A(ManyToOne * ) ->C(ManyToOne 1)
I need to iterate above A with A.B and need to contains C Collections.
@Name("A")
| @Table(name="A")
| @Entity
| public class A implements Serializable{
|
| @Id @GeneratedValue
| private Long id;
|
| @ManyToOne
| @JoinColumn(name="b_id")
| private B b;
|
| @ManyToOne
| @JoinColumn(name="cl_id")
| private C c;
@Entity
| @Name("B")
| @Table(name="B")
| public class B implements Serializable{
| @Id @GeneratedValue(strategy=GenerationType.AUTO)
| private int id;
| @NotNull
| private String bezeichnung;
|
| @OneToMany(mappedBy="b",cascade=CascadeType.ALL, fetch=FetchType.LAZY)
| @OrderBy("bezeichnung")
| private List<C> c;
|
| @OneToMany(mappedBy="b",cascade=CascadeType.ALL, fetch=FetchType.LAZY)
| @OrderBy("kennzeichen")
| private Set<A> a;
@Entity
@Name("C")
@Table(name="C")
public class C implements Serializable {
@Id @GeneratedValue(strategy=GenerationType.AUTO)
private long id;
@NotNull
private String bezeichnung;
@ManyToOne
@JoinColumn(name="b_id")
private B b;
@OneToMany(mappedBy="c",cascade=CascadeType.ALL, fetch=FetchType.EAGER)
private Set A = new HashSet();
i need to iterate above A that contains B and have to contains List of C.
How can i do that?
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4042618#4042618
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4042618
17 years, 4 months