1

当我使用 Spring 获得的实体管理器持久化实体时,我面临以下问题。

java.lang.IllegalArgumentException: Object: org.tts.maqraa.data.Daralquran@183eae7 is not a known entity type.
javax.faces.FacesException: #{configurationChecker.check}: java.lang.IllegalArgumentException: Object: org.tts.maqraa.data.Daralquran@183eae7 is not a known entity type.
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:118)
    at javax.faces.component.UICommand.broadcast(UICommand.java:315)
    at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:794)
    at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:1259)
    at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:81)
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:169)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:999)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:565)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:309)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)
Caused by: javax.faces.el.EvaluationException: java.lang.IllegalArgumentException: Object: org.tts.maqraa.data.Daralquran@183eae7 is not a known entity type.
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:102)
    at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:102)
    ... 23 more
Caused by: java.lang.IllegalArgumentException: Object: org.tts.maqraa.data.Daralquran@183eae7 is not a known entity type.
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3484)
    at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeCloneWithReferences(RepeatableWriteUnitOfWork.java:378)
    at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3455)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:486)
    at org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:463)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.orm.jpa.ExtendedEntityManagerCreator$ExtendedEntityManagerInvocationHandler.invoke(ExtendedEntityManagerCreator.java:365)
    at $Proxy8.merge(Unknown Source)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
    at $Proxy8.merge(Unknown Source)
    at org.tts.maqraa.service.AbstractMaqraaService.store(AbstractMaqraaService.java:60)
    at org.tts.maqraa.service.DarAlQuranService.createNewDarAlQuran(DarAlQuranService.java:47)
    at org.tts.maqraa.service.test.ConfigurationChecker.check(ConfigurationChecker.java:63)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.el.parser.AstValue.invoke(AstValue.java:264)
    at org.apache.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:278)
    at com.sun.faces.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:105)
    at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:88)
    ... 24 more.

我在哪里使用以下技术

  • 阿帕奇雄猫 7.
  • Eclipse 链接 2.3.2。
  • 春天 3.0。
  • JSF 2.0 莫哈拉。

您还可以找到 Daralquran 实体以确保正确映射实体。

@Entity
public class Daralquran implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    private int id;

    @Temporal( TemporalType.DATE)
    @Column(name="Established_Date")
    private Date establishedDate;

    @Column(name="Full_Name")
    private String fullName;

    @Column(name="Mobile_Number")
    private String mobileNumber;

    private String note;

    @Column(name="Phone_no")
    private String phoneNo;

    //bi-directional many-to-one association to City
    @ManyToOne(cascade={CascadeType.ALL})
    @JoinColumn(name="city_Id")
    private City city;

    //bi-directional many-to-one association to Country
    @ManyToOne(cascade={CascadeType.ALL})
    @JoinColumn(name="country_Id")
    private Country country;

    //bi-directional many-to-one association to User
    @ManyToOne(cascade={CascadeType.ALL})
    @JoinColumn(name="supervisor_id")
    private User user;

    //bi-directional many-to-many association to User
    @ManyToMany(mappedBy="daralqurans2", fetch=FetchType.EAGER)
    private List<User> users;

    public Daralquran() {
    }

    public int getId() {
        return this.id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public Date getEstablishedDate() {
        return this.establishedDate;
    }

    public void setEstablishedDate(Date establishedDate) {
        this.establishedDate = establishedDate;
    }

    public String getFullName() {
        return this.fullName;
    }

    public void setFullName(String fullName) {
        this.fullName = fullName;
    }

    public String getMobileNumber() {
        return this.mobileNumber;
    }

    public void setMobileNumber(String mobileNumber) {
        this.mobileNumber = mobileNumber;
    }

    public String getNote() {
        return this.note;
    }

    public void setNote(String note) {
        this.note = note;
    }

    public String getPhoneNo() {
        return this.phoneNo;
    }

    public void setPhoneNo(String phoneNo) {
        this.phoneNo = phoneNo;
    }

    public City getCity() {
        return this.city;
    }

    public void setCity(City city) {
        this.city = city;
    }

    public Country getCountry() {
        return this.country;
    }

    public void setCountry(Country country) {
        this.country = country;
    }

    public User getUser() {
        return this.user;
    }

    public void setUser(User user) {
        this.user = user;
    }

    public List<User> getUsers() {
        return this.users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }   
    }

您还可以找到 persistence.xml 文件的内容

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
    version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
    <persistence-unit name="Maqraa">
        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <class>org.tts.maqraa.data.DarAlquranManager</class>
        <class>org.tts.maqraa.data.DoorAlquranGM</class>
        <class>org.tts.maqraa.data.QuranTeacher</class>
        <class>org.tts.maqraa.data.ScientificOfficer</class>
        <class>org.tts.maqraa.data.SystemAdmin</class>
        <class>org.tts.maqraa.data.City</class>
        <class>org.tts.maqraa.data.Country</class>
        <class>org.tts.maqraa.data.Daralquran</class>
        <class>org.tts.maqraa.data.HalaqaAchievement</class>
        <class>org.tts.maqraa.data.HalaqaAssociation</class>
        <class>org.tts.maqraa.data.Halaqa</class>
        <class>org.tts.maqraa.data.MemorizationProgram</class>
        <class>org.tts.maqraa.data.Permission</class>
        <class>org.tts.maqraa.data.Phase</class>
        <class>org.tts.maqraa.data.PhasesAttendance</class>
        <class>org.tts.maqraa.data.Recitation</class>
        <class>org.tts.maqraa.data.Role</class>
        <class>org.tts.maqraa.data.Student</class>
        <class>org.tts.maqraa.data.User</class>
        <properties>
            <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/maqraa" />
            <property name="javax.persistence.jdbc.user" value="root" />
            <property name="javax.persistence.jdbc.password" value="root" />
            <property name="eclipselink.ddl-generation" value="none" />
            <property name="eclipselink.ddl-generation.output-mode" value="database" />
        </properties>
    </persistence-unit>
</persistence>

您还可以找到 spring 元数据配置 maqraa-module-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:annotation-config />

    <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/maqraa" />
        <property name="username" value="root" />
        <property name="password" value="root" />
    </bean>

    <bean id="jpaDialect" class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />

    <bean id="jpaVendorAdapter"
        class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
        <property name="showSql" value="true" />
    </bean>

    <bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="Maqraa" />
        <property name="dataSource" ref="dataSource" />
        <property name="jpaVendorAdapter" ref="jpaVendorAdapter" />
        <property name="jpaDialect" ref="jpaDialect" />
        <property name="loadTimeWeaver">
            <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
        </property>
    </bean>

    <bean id="darAlquranService" class="org.tts.maqraa.service.DarAlQuranService"></bean>

    <bean id="configurationChecker" class="org.tts.maqraa.service.test.ConfigurationChecker"></bean>

</beans>

那么,任何人都可以帮助我使 em 正常工作。

感谢穆罕默德·阿米尔。

4

3 回答 3

1

这是一个类加载器问题,您不知何故加载了同一个类的两个不同版本。

确保您没有在两个不同的地方部署这个类,并且正确配置了 Spring。也许尝试一些 Spring 示例。

你要重新部署?如果您尚未关闭旧的 EntityManagerFactory,您可能会收到此错误。尝试重新启动服务器。

你所有的课程都有同样的错误,还是做了一些工作?

于 2012-05-09T14:40:14.240 回答
1

我得到它 :),

因为我使用 tomcat 7 来运行应用程序,它不是 EE 约束器,因此它必须使用“LocalEntityManagerFactory”而不是“LocalContainerEntityManagerFactory”。

这样,您将能够调用实体管理器方法并考虑交易。

总的来说,这是最后一个 maqraa-module-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="
            http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd
            http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
            http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">

    <context:annotation-config />
    <!-- <context:component-scan base-package="org.tts.maqraa.data" annotation-config="true"/> -->
    <bean
        class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url" value="jdbc:mysql://localhost:3306/maqraa" />
        <property name="username" value="maqraa" />
        <property name="password" value="maqraa" />
    </bean>

    <bean id="jpaDialect"
        class="org.springframework.orm.jpa.vendor.EclipseLinkJpaDialect" />

    <bean id="jpaVendorAdapter"
        class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
        <property name="database" value="MYSQL" />
        <property name="showSql" value="true" />
    </bean>

    <bean id="entityManagerFactory"
        class="org.springframework.orm.jpa.LocalEntityManagerFactoryBean">
        <property name="persistenceUnitName" value="Maqraa" />
    </bean>

    <bean id="configurationChecker" class="org.tts.maqraa.service.test.ConfigurationChecker"></bean>

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"
        p:entityManagerFactory-ref="entityManagerFactory" />

    <!-- Activates various annotations to be detected in bean classes for eg 
        @Autowired -->
    <!-- <context:annotation-config/> -->
    <!-- enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="transactionManager" />

</beans> 

谢谢大家, Mohammed Amr。

于 2012-05-10T10:21:51.943 回答
0

也许您需要专门 GenerationType ,而不是使用 GenerationType.Auto.Try it。我不确定。同样的案例在这里

于 2012-05-09T09:16:54.277 回答