我正在使用学院提供的springmvc-hibernate-mysql项目模板来做一个项目。
这个项目有一个抽象类actor,还有6个扩展类actor:administrator、explorer、manager、ranger、auditor和sponsor。
另一方面,有些消息具有发送者(actor)、接收者集合(actor)和其他各种无关紧要的属性。
问题是,我不能做涉及从数据库中选择一个发件人或收件人不是ranger的邮件的操作。它在其他任何情况下都能正常工作。
我有一个名为querydatabase的实用工具,可以在eclipse控制台上进行查询。在这一层中,转换器并不重要,因为它是简单的查询,所以问题不在转换器上,因为即使在查询上我也有这个问题。
我无法选择包含管理员发件人的邮件:
> select m from Message m where m.sender.id=342;
javax.persistence.EntityNotFoundException: Unable to find domain.Actor with id 342
但是,我可以选择该邮件的发件人:
> select m.sender from Message m where m.sender.id=342;
1 object selected
domain.Administrator{id=342, version=0}
domain.DomainEntity::id: int = 342
domain.DomainEntity::version: int = 0
domain.Actor::name: java.lang.String = "Mark"
domain.Actor::surname: java.lang.String = "Kilo"
domain.Actor::email: java.lang.String = "markkilo@go.es"
domain.Actor::phone: java.lang.String = "6662637633"
domain.Actor::address: java.lang.String = "Ulises Street,12,London"
domain.Actor::isSuspicious: boolean = false
domain.Actor::isBanned: boolean = false
domain.Actor::folders: java.util.Collection = [domain.Folder{id=343, version=0}, domain.Folder{id=344, version=0}, domain.Folder{id=345, version=0}, domain.Folder{id=346, version=0}, domain.Folder{id=347, version=0}, domain.Folder{id=348, version=0}]
domain.Actor::socialEntities: java.util.Collection = []
domain.Actor::userAccount: security.UserAccount = security.UserAccount{id=329, version=0}
我还可以通过id选择一个参与者作为管理员:
> select a from Actor a where a.id=342;
1 object selected
domain.Administrator{id=342, version=0}
domain.DomainEntity::id: int = 342
domain.DomainEntity::version: int = 0
domain.Actor::name: java.lang.String = "Mark"
domain.Actor::surname: java.lang.String = "Kilo"
domain.Actor::email: java.lang.String = "markkilo@go.es"
domain.Actor::phone: java.lang.String = "6662637633"
domain.Actor::address: java.lang.String = "Ulises Street,12,London"
domain.Actor::isSuspicious: boolean = false
domain.Actor::isBanned: boolean = false
domain.Actor::folders: java.util.Collection = [domain.Folder{id=343, version=0}, domain.Folder{id=344, version=0}, domain.Folder{id=345, version=0}, domain.Folder{id=346, version=0}, domain.Folder{id=347, version=0}, domain.Folder{id=348, version=0}]
domain.Actor::socialEntities: java.util.Collection = []
domain.Actor::userAccount: security.UserAccount = security.UserAccount{id=329, version=0}
而且,如我所说,我可以选择一个发件人/收件人是管理员的邮件:
> select m from Message m where m.sender.id=403;
11 objects selected
domain.Message{id=472, version=0}
domain.DomainEntity::id: int = 472
domain.DomainEntity::version: int = 0
domain.Message::LOW: java.lang.String = "LOW"
domain.Message::NEUTRAL: java.lang.String = "NEUTRAL"
domain.Message::HIGH: java.lang.String = "HIGH"
domain.Message::subject: java.lang.String = "House Fix"
domain.Message::body: java.lang.String = "We have to fix the widnow in the liing room"
domain.Message::moment: java.util.Date = <<2016-07-12 00:00:00.0>>
domain.Message::priority: java.lang.String = "HIGH"
domain.Message::sender: domain.Actor = domain.Ranger{id=403, version=0}
domain.Message::recipients: java.util.Collection = [domain.Ranger{id=409, version=0}]
etc
但是,我可以查询具有“administrator”或“explorer”类型属性以及该具体类型的示例属性的实体。
所以,问题只是当我查询一个具有actor(abstract)属性的实体时,示例化的属性是一个扩展actor类,而不是ranger。
我被告知要在所有类上放置的所有标记和扩展都是相同的,所以,知道哪里会出错吗?
域和存储库文件上的所有标记和导入的库都是相同的,并且它们都扩展了actor。
游侠既不是第一个示例化的类,也不是最后一个示例化的类。
我在游骑兵身上找不到任何能让他们满意的东西。
如果你需要任何其他代码,让我知道,但我甚至不知道什么是有用的,因为一切似乎多余的我。
谢谢你的阅读。
编辑:忘了说,这不只是发生在消息。社会性也有类似的特点。
edit2:准备添加实体代码,以防有人发现任何奇怪的东西:
信息:
@Entity
@Access(AccessType.PROPERTY)
public class Message extends DomainEntity {
// Priority Values -----------------------------------------------------------------
public static final String LOW = "LOW";
public static final String NEUTRAL = "NEUTRAL";
public static final String HIGH = "HIGH";
private String subject;
private String body;
private Date moment;
private String priority;
private Actor sender;
private Collection<Actor> recipients;
@NotBlank
public String getSubject() {
return this.subject;
}
public void setSubject(final String subject) {
this.subject = subject;
}
@NotBlank
public String getBody() {
return this.body;
}
public void setBody(final String body) {
this.body = body;
}
@DateTimeFormat(pattern = "dd.MM.yyyy HH:mm:ss.SSSZ")
@Temporal(TemporalType.TIMESTAMP)
public Date getMoment() {
return this.moment;
}
public void setMoment(final Date moment) {
this.moment = moment;
}
@NotBlank
@Pattern(regexp = "^" + LOW + "|" + NEUTRAL + "|" + HIGH + "$")
public String getPriority() {
return this.priority;
}
public void setPriority(final String priority) {
this.priority = priority;
}
@NotNull
@Valid
@ManyToOne(optional = false)
public Actor getSender() {
return this.sender;
}
public void setSender(final Actor sender) {
this.sender = sender;
}
@NotEmpty
@Valid
@ManyToMany
public Collection<Actor> getRecipients() {
return this.recipients;
}
public void setRecipients(final Collection<Actor> recipients) {
this.recipients = recipients;
}
}
演员:
@Entity
@Access(AccessType.PROPERTY)
public class Actor extends DomainEntity {
private String name;
private String surname;
private String email;
private String phone;
private String address;
private boolean isSuspicious;
private boolean isBanned;
private Collection<Folder> folders;
private Collection<SocialEntity> socialEntities;
private UserAccount userAccount;
@NotBlank
public String getName() {
return this.name;
}
public void setName(final String name) {
this.name = name;
}
@NotBlank
public String getSurname() {
return this.surname;
}
public void setSurname(final String surname) {
this.surname = surname;
}
@Email
public String getEmail() {
return this.email;
}
public void setEmail(final String email) {
this.email = email;
}
public String getPhone() {
return this.phone;
}
public void setPhone(final String phone) {
this.phone = phone;
}
public String getAddress() {
return this.address;
}
public void setAddress(final String address) {
this.address = address;
}
@OneToMany(cascade = CascadeType.ALL)
@NotNull
@Valid
public Collection<Folder> getFolders() {
return this.folders;
}
public void setFolders(final Collection<Folder> folders) {
this.folders = folders;
}
@ElementCollection
@OneToMany(mappedBy = "actor")
@NotNull
public Collection<SocialEntity> getSocialEntities() {
return this.socialEntities;
}
public void setSocialEntities(final Collection<SocialEntity> socialEntities) {
this.socialEntities = socialEntities;
}
@OneToOne(cascade = CascadeType.ALL)
@NotNull
public UserAccount getUserAccount() {
return this.userAccount;
}
public void setUserAccount(final UserAccount userAccount) {
this.userAccount = userAccount;
}
public boolean getIsSuspicious() {
return isSuspicious;
}
public void setIsSuspicious(boolean isSuspicious) {
this.isSuspicious = isSuspicious;
}
public boolean getIsBanned() {
return isBanned;
}
public void setIsBanned(boolean isBanned) {
this.isBanned = isBanned;
}
护林员:
@Entity
@Access(AccessType.PROPERTY)
public class Ranger extends Actor {
private Curricula curricula;
private Collection<Trip> trips;
@NotNull
@OneToOne(optional = true, cascade = CascadeType.ALL)
public Curricula getCurricula() {
return this.curricula;
}
@Valid
@OneToMany(mappedBy = "ranger")
public Collection<Trip> getTrips() {
return this.trips;
}
public void setCurricula(final Curricula curricula) {
this.curricula = curricula;
}
public void setTrips(final Collection<Trip> trips) {
this.trips = trips;
}
例如,管理员。如果您需要更多信息,请告诉我:
@Entity
@Access(AccessType.PROPERTY)
public class Administrator extends Actor{
}
edit3:为演员填充bean的例子;
管理员:
<bean id="admin1" class="domain.Administrator">
<property name="name" value="Mark" />
<property name="surname" value="Kilo" />
<property name="email" value="markkilo@go.es" />
<property name="phone" value="6662637633" />
<property name="address" value="Ulises Street,12,London" />
<property name="folders">
<list>
<ref bean="sys-admin1"/>
<ref bean="inbox-admin1" />
<ref bean="outbox-admin1" />
<ref bean="notifbox-admin1" />
<ref bean="trashbox-admin1" />
<ref bean="spambox-admin1" />
</list>
</property>
<property name="socialEntities">
<list>
</list>
</property>
<property name="userAccount" ref="adminUserAccount" />
<property name="isSuspicious" value="false" />
<property name="isBanned" value="false" />
</bean>
护林员:
<bean id="ranger1" class="domain.Ranger">
<property name="name" value="Paco" />
<property name="surname" value="Pepe" />
<property name="email" value="franciscojose@gmail.com" />
<property name="phone" value="953547272" />
<property name="address" value="C\ Alpha nº69" />
<property name="userAccount" ref="rangerUserAccount" />
<property name="isSuspicious" value="false" />
<property name="isBanned" value="false" />
<property name="folders">
<list>
<ref bean="inbox-ranger1" />
<ref bean="outbox-ranger1" />
<ref bean="notifbox-ranger1" />
<ref bean="trashbox-ranger1" />
<ref bean="spambox-ranger1" />
</list>
</property>
<property name="socialEntities">
<list>
<ref bean="socialEntity3" />
<ref bean="socialEntity4" />
</list>
</property>
<property name="curricula" ref="curricula1">
</property>
<property name="trips">
<list>
<ref bean="trip1" />
</list>
</property>
</bean>
1条答案
按热度按时间cnh2zyt31#
看起来您的关系message.sender->actor是通过中间表message\u senders或类似的方式创建的:
在表actors\u senders中删除了actor\u id=342的记录。
这就是我在看到你们实体的代码之前所能说的一切。
编辑:
在添加实体代码之后:您有一个抽象类actor,它不是真正抽象的,也不适用于java或hibernate。这是非常混乱的(包括冬眠)。
换个演员:
也许这会有帮助。