1
您好,我正在使用Java EE 7。代碼得到了以下結構。持久單元錯誤更多2個EntityManagers 1個持續單元?
模型 - >實體Bean
業務 - >服務類模型(每包含的EntityManager)
演講 - 對服務>命名SessionScoped豆類與@EJB
當我測試程序只有1服務/ EntityManager一切正常,但現在當我添加第二個服務級我得到這個錯誤:
>
SEVERE: Exception while invoking class org.glassfish.persistence.jpa.JPADeployer prepare method
SEVERE: javax.persistence.PersistenceException: Exception [EclipseLink-28018] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.EntityManagerSetupException
Exception Description: Predeployment of PersistenceUnit [watchuwantPU] failed.
Internal Exception: Exception [EclipseLink-7250] (Eclipse Persistence Services - 2.5.0.v20130507-3faac2b): org.eclipse.persistence.exceptions.ValidationException
Exception Description: [class model.Tag] uses a non-entity [class java.lang.String] as target entity in the relationship attribute [field beschreibung].
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.createPredeployFailedPersistenceException(EntityManagerSetupImpl.java:1950)
at org.eclipse.persistence.internal.jpa.EntityManagerSetupImpl.predeploy(EntityManagerSetupImpl.java:1941)
at org.eclipse.persistence.jpa.PersistenceProvider.createContainerEntityManagerFactory(PersistenceProvider.java:322)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.loadPU(PersistenceUnitLoader.java:199)
at org.glassfish.persistence.jpa.PersistenceUnitLoader.<init>(PersistenceUnitLoader.java:107)
at org.glassfish.persistence.jpa.JPADeployer$1.visitPUD(JPADeployer.java:223)
at org.glassfish.persistence.jpa.JPADeployer$PersistenceUnitDescriptorIterator.iteratePUDs(JPADeployer.java:510)
at org.glassfish.persistence.jpa.JPADeployer.createEMFs(JPADeployer.java:230)
at org.glassfish.persistence.jpa.JPADeployer.prepare(JPADeployer.java:168)
的persistence.xml
<persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">
<persistence-unit name="watchuwantPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>watchuwant</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/>
</properties>
</persistence-unit>
</persistence>
FilmService.java
@Stateless
公共類FilmService {
@PersistenceContext(name="watchuwantPU", unitName = "watchuwantPU")
private EntityManager em;
public void add(Film Film){
em.persist(Film);
}
public List<Film> findAll(){
return em.createQuery("select f from Film f order by f.id").getResultList();
}
}
LizenzPM.java
@SessionScoped
@Named
public class LizenzPM implements Serializable{
private String lizenzgeber;
private String lizenztyp;
private String lizenzurl;
private Date erteiltAm;
@EJB
private LizenzService service;
Film.java實體
@Entity
public class Film implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
private String titel;
@OneToMany(mappedBy = "parent", cascade=CascadeType.ALL, orphanRemoval=true)
private List<Tag> tags = new LinkedList<>();
Tag.class實體
@Entity
public class Tag implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
@ManyToOne(optional = false)
private String beschreibung;
private Film parent;
此外,請注意,按照慣例,持久性配置是在名爲'persistence.xml'的文件中完成的。 –
如果編輯過我的帖子並插入新的錯誤信息。我也有persistence.xml – user2742409
好吧,現在我明白了。看起來你在一個實體類中的對象關係映射中有一些錯誤。你可以發佈「標籤」類的內容嗎?它看起來像是在一個String類型的字段上定義了一個關係(也許是一個@ ManyToOne註解),這是一種錯誤。 –