【发布时间】:2012-03-31 03:04:45
【问题描述】:
知道如何在 jpa 中访问多对一关系中的 mappedsuper 类。这是我的代码 sn-p。
Message 是非实体映射的超类(没有消息表) SystemMessage是一个实体类表名是SYSTEM_MESSAGE//联合子类 OrganizationMessage是一个实体类表名是ORGANIZATION_MESSAGE//联合子类
当我尝试从 ORGANIZATION_NOTIFICATION 访问组织通知域对象时 组织通知表有message_id列(Message)多对多关系。
它没有加载并且它抛出的消息不是实体。即使我尝试了@entity 而不是@mappedsuperclass,但它没有加载消息。我应该通过组织通知访问系统消息和组织消息
@MappedSuperClass
@Inheritance( strategy = InheritanceType.TABLE_PER_CLASS )
public class Message extends BaseDomain implements Comparable<Message>
{
private final static Logger log = Logger.getLogger( Message.class );
@Id
@Column( name = "MESSAGE_ID" )
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "MESSAGE_PK_SQ" )
@SequenceGenerator( name = "MESSAGE_PK_SQ", sequenceName = "MESSAGE_PK_SQ", allocationSize = 1 )
private Long id;
@Column(name="MESSAGE_NAME")
private String name;
}
@Entity
@Table( name = "SYSTEM_MESSAGE" )
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
public class SystemMessage extends Message
{
//some persitant variables
}
@Entity
@Table( name = "ORGANIZATION_MESSAGE" )
@Inheritance( strategy = InheritanceType.SINGLE_TABLE )
public class OrganizationMessage extends Message
{
//some persitant variables
}
@SuppressWarnings( "serial" )
@Entity
@Table( name = "ORGANIZATION_NOTIFICATION" )
public class OrganizationNotification extends BaseDomain implements Comparable<OrganizationNotification>
{
@Id
@Column( name = "ORGANIZATION_NOTIFICATION_ID" )
@GeneratedValue( strategy = GenerationType.SEQUENCE, generator = "org_notification_pk_sq" )
@SequenceGenerator( name = "org_notification_pk_sq", sequenceName = "org_notification_pk_sq", allocationSize = 1 )
private Long id;
//Here is the issue. when i try to access message it says it is not entity otherwise it is not loading if i use entity in message and not saving.
@ManyToOne( targetEntity = Message.class )
@JoinColumn( name = "MESSAGE_ID", insertable = true, updatable = true, nullable = false,referencedColumnName="MESSAGE_ID" )
private Message message;
}
您能否就这个问题给我任何建议。
【问题讨论】:
标签: jpa