Hibernate mapPingeException - Fremdschlüssel -Zählung Nichtübereinstimmung mit referenzierter PrimärschlüsselJava

Java-Forum
Anonymous
 Hibernate mapPingeException - Fremdschlüssel -Zählung Nichtübereinstimmung mit referenzierter Primärschlüssel

Post by Anonymous »

Ich begegne einen Fehler, wenn ich versuche, Daten mit JPA und Hibernate zu speichern. Die Fehlermeldung lautet: < /p>

Code: Select all

Caused by: org.hibernate.MappingException: Foreign key (FKi3uxs48nod3arim7hhpwx1anb:role_group [app_group_id])) must have same number of columns as the referenced primary key (app_group [id, app_id, group_id])
< /code>
Ich habe die folgenden Tabellendefinitionen und Entitätskräfte: < /p>
App_Group Tabelle Erstellung: < /p>
create table app_group
(
id           varchar(36) not null,
group_id     varchar(36) not null,
app_id       varchar(36) not null,
primary key (id),
unique (group_id, app_id),
constraint app_group_group_fk foreign key (group_id) references `group` (id),
constraint app_group_app_fk foreign key (app_id) references `app` (id)
);
< /code>
AppGroup JPA Entity: < /p>
@Entity
@Table(name = "app_group")
public class AppGroup implements Serializable {
@Id
@Size(min = 36, max = 36)
protected String id;

@ManyToOne
@JoinColumn(name = "app_id")
private App app;

@ManyToOne
@JoinColumn(name = "group_id")
private Group group;

@OneToMany(mappedBy = "appGroup", cascade = CascadeType.ALL, orphanRemoval = true)
private Set groupRoles = new HashSet();
}
< /code>
Rollengruppe Tabelle Erstellung: < /p>
create table role_group
(
id           varchar(36) not null,
group_id     varchar(36) not null,
role_id       varchar(36) not null,
app_group_id varchar(36) not null,
primary key (id),
unique (group_id, role_id),
constraint role_group_group_fk foreign key (group_id) references `group` (id),
constraint role_group_role_fk foreign key (role_id) references `role` (id),
constraint role_group_app_group_fk foreign key (app_group_id) references `app_group` (id)
);
< /code>
Rollengruppe JPA Entity: < /p>
@Entity
@Table(name = "role_group")
@Accessors(fluent = true)
public class RoleGroup {
@Id
@Size(min = 36, max = 36)
protected String id;

@ManyToOne
@JoinColumn(name = "role_id")
private Role role;

@ManyToOne
@JoinColumn(name = "group_id")
private Group group;

@ManyToOne
@JoinColumn(name = "app_group_id")
private AppGroup appGroup;
}
Problem:
Die Tabelle app_group enthält eine primäre Schlüssel -ID und eine eindeutige Einschränkung (Group_id, app_id) , die gut funktionieren sollte. Das ist im Schema nicht der Fall. Und wie kann ich dieses Problem lösen?

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post