首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >持续单位错误多2 EntityManagers 1持久单位?

持续单位错误多2 EntityManagers 1持久单位?
EN

Stack Overflow用户
提问于 2014-03-01 13:33:28
回答 1查看 242关注 0票数 1

嗨,我正在使用Java 7。代码得到了以下结构。

模型->实体Beans

模型的业务->服务类(每个类包含一个EntityManager)

表示->服务上带有@EJB的命名SessionScoped Beans

当我仅用一个服务/ EntityManager测试程序时,一切都正常,但是现在当我添加第二个服务类时,我得到了以下错误:

代码语言:javascript
复制
>

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

代码语言:javascript
复制
<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

代码语言:javascript
复制
@Stateless

公共类FilmService {

代码语言:javascript
复制
@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

代码语言:javascript
复制
@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实体

代码语言:javascript
复制
@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实体

代码语言:javascript
复制
@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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-01 13:48:25

我认为持久化单元名是watchuwantPU,而不是LizenzService。检查@PersistenceContext注释。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22115043

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档