Skip to main content

complicated M-M relationship

1 reply [Last post]
lekk
Offline
Joined: 2006-09-25

Hello,

I am trying to map this relationship:

Usuario(1) <-> (M)UsuarioSubgrupo(M) <-> (1)Subgrupo

Where Subgrupo has a composite PK:
Grupo(1) <-> (N)Subgrupo

The problem is I am not able to update an Usuario object. It sounds like the mapping on the Usuario.class for Subgrupo object is wrong, or something similar.

The message error is:
Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2006.4 (Build 060412)): oracle.toplink.essentials.exceptions.DatabaseException
Internal Exception: java.sql.SQLException: ORA-00904: "CD_GRUPO": identificador inválido
Error Code: 904
Call:SELECT DT_INCLU, CD_USUAR_ALTER, CD_USUAR, DT_ALTER, CD_SUBGR, CD_USUAR_INCLU, CD_GRUPO FROM USUARIO_SUBGRUPO WHERE (CD_USUAR = ?)
bind => [1]
Query:ReadAllQuery(sysgroups.entity.UsuarioSubgrupo)
at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:303)
at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.basicExecuteCall(DatabaseAccessor.java:551)
at oracle.toplink.essentials.internal.databaseaccess.DatabaseAccessor.executeCall(DatabaseAccessor.java:437)
at oracle.toplink.essentials.threetier.ServerSession.executeCall(ServerSession.java:464)
...

Tables:
----------
Grupo
CD_GRUPO (pk)
DS_GRUPO

Subgrupo
CD_SUBGR (pk)
CD_GRUPO (pk-fk)
DS_SUBGR

UsuarioSubgrupo
CD_USUAR (pk-fk)
CD_SUBGR (pk-fk)

Usuario
CD_USUAR (pk)
NM_USUAR

Relevant code:

Usuario.class
@Id
@Column(name = "CD_USUAR", nullable = false)
@SequenceGenerator(name="SqUsuario",sequenceName="SQ_USUARIO", allocationSize=20)
@GeneratedValue(strategy=javax.persistence.GenerationType.SEQUENCE, generator="SqUsuario")
private Long cdUsuar;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "usuario")
private java.util.Collection usuarioSubgrupoCollection;

@IdClass(UsuarioSubgrupoPK.class)
UsuarioSubgrupo.class
@Id
@Column(name="CD_SUBGR", nullable = false, insertable = false, updatable = false)
private Long cdSubgr;

@Id
@Column(name="CD_USUAR", nullable = false, insertable = false, updatable = false)
private Long cdUsuar;

@JoinColumn(name = "CD_USUAR", referencedColumnName = "CD_USUAR")
@ManyToOne
private Usuario usuario;

@JoinColumns({
@JoinColumn(name = "CD_GRUPO", referencedColumnName = "CD_GRUPO"),
@JoinColumn(name = "CD_SUBGR", referencedColumnName = "CD_SUBGR")
})
@ManyToOne
private Subgrupo subgrupo;

@IdClass(SubgrupoPK.class)
Subgrupo.class
@Id
@Column(name="CD_GRUPO", nullable = false, insertable = false, updatable = false)
private Long cdGrupo;

@Id
@Column(name="CD_SUBGR", nullable = false)
@SequenceGenerator(name="SqSubgrupo",sequenceName="SQ_SUBGRUPO", allocationSize=20)
@GeneratedValue(strategy=javax.persistence.GenerationType.SEQUENCE, generator="SqSubgrupo")
private Long cdSubgr;

@ManyToOne
@JoinColumn(name = "CD_GRUPO", referencedColumnName = "CD_GRUPO")
private Grupo grupo;

@JoinColumn(name = "CD_USUAR", referencedColumnName = "CD_USUAR", updatable=false, insertable=false)
@ManyToOne
private Usuario usuario;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "subgrupo")
private java.util.Collection usuarioSubgrupoCollection;

Grupo.class
@Id
@Column(name = "CD_GRUPO", nullable = false)
@SequenceGenerator(name="SqGrupo",sequenceName="SQ_GRUPO", allocationSize=20)
@GeneratedValue(strategy=javax.persistence.GenerationType.SEQUENCE, generator="SqGrupo")
private Long cdGrupo;

@OneToMany(cascade = CascadeType.ALL, mappedBy = "grupo")
private java.util.Collection subgrupoCollection;

Any ideas?

Thanks a lot!

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
ss141213
Offline
Joined: 2005-03-30

That error is justified because you [b]don't[/b] have CD_GRUPO column in UsuarioSubgrupo table. This is specified as one of the JoinColumns in [i]@ManyToOne private Subgrupo subgrupo[/i].

Hope this helps,
Sahoo