【发布时间】:2014-10-12 01:33:35
【问题描述】:
我有下面的表和下面的关系表:,它的组合PK如下:
UserRole.java
@RooJavaBean
@RooJpaEntity(identifierType = UserRolePK.class, versionField = "", table = "UserRole", schema = "dbo")
@RooDbManaged(automaticallyDelete = true)
@RooToString(excludeFields = { "idApplication", "idRole", "idUserName" })
public class UserRole {
}
UserRole_Roo_DbManaged.aj
@ManyToOne
@JoinColumn(name = "IdApplication", referencedColumnName = "IdApplication", nullable = false, insertable = false, updatable = false)
private Application UserRole.idApplication;
@ManyToOne
@JoinColumn(name = "IdRole", referencedColumnName = "IdRole", nullable = false, insertable = false, updatable = false)
private Role UserRole.idRole;
@ManyToOne
@JoinColumn(name = "IdUserName", referencedColumnName = "IdUserName", nullable = false, insertable = false, updatable = false)
private Users UserRole.idUserName;
而且还存在一个PK表:
@RooIdentifier(dbManaged = true)
public final class UserRolePK {}
及其标识符类(UserRolePK_Roo_Identifier.aj)
privileged aspect UserRolePK_Roo_Identifier {
declare @type: UserRolePK: @Embeddable;
@Column(name = "IdRole", nullable = false)
private Long UserRolePK.idRole;
@Column(name = "IdUserName", nullable = false, length = 16)
private String UserRolePK.idUserName;
@Column(name = "IdApplication", nullable = false)
private Long UserRolePK.idApplication;
我设置要保存的服务对象的方式是:
UserRole userRole= new UserRole();
userRole.setIdApplication(app);
userRole.setIdRole(invited);
userRole.setIdUserName(user);
appService.saveURole(userRole);
app 之前已设置并保存(同一事务),以及 invited 和 >用户个对象。 由于用户(来自具有复合 PK 的 Users 表: IdUserName 这是一个 String ),定义如下,否则不起作用。
@RooJavaBean
@RooJpaEntity(versionField = "", table = "Users", schema = "dbo")
@RooDbManaged(automaticallyDelete = true)
@RooToString(excludeFields = { "quotations", "taxes", "userRoles", "idCompany", "idPreferredLanguage" })
public class Users {
@Id
//@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "IdUserName", length = 16, insertable = true, updatable = true)
private String idUserName;
}
所以,我得到的错误是:
org.springframework.orm.jpa.JpaSystemException: org.hibernate.id.IdentifierGenerationException: null id generated for:class com.domain.UserRole; nested exception is javax.persistence.PersistenceException: org.hibernate.id.IdentifierGenerationException: null id generated for:class com.domain.UserRole
【问题讨论】:
标签: spring jpa jpa-2.0 spring-data spring-roo