1
不知道如何訪問多對一關係船mappedsuper類JPA。這是我的代碼片段。JPA - 不能訪問非實體@MappedSuperclass在多對一關係
消息在非實體映射超(用於消息沒有表) 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;
}
同時訪問系統信息與組織的消息,你能告訴我任何關於此問題的建議。
謝謝!我做了更多的改變。我將Message具體類更改爲抽象消息類。現在工作正常。 – JavaTech 2012-03-16 14:52:16