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>

また、春のメタデータ構成 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

これはクラスローダーの問題です。どういうわけか、同じクラスの2つの異なるバージョンがロードされています。

このクラスを2つの異なる場所に展開しておらず、Springが正しく構成されていることを確認してください。おそらく、春の例のいくつかを試してみてください。

再デプロイしていますか?古いEntityManagerFactoryを閉じていない場合、このエラーが発生する可能性があります。サーバーを再起動してみてください。

すべてのクラスで同じエラーが発生しますか、それとも何らかの作業を行いますか?

于 2012-05-09T14:40:14.240 に答える
1

わかった :)、

アプリケーションの実行にTomcat 7を使用していますが、これはEEコントレーナーではないため、「LocalContainerEntityManagerFactory」ではなく「LocalEntityManagerFactory」を使用する必要があります。

これにより、エンティティ マネージャーのメソッドを呼び出すことができ、トランザクションを考慮することができます。

完全に、これが最後の 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> 

ありがとう、モハメド・アムル。

于 2012-05-10T10:21:51.943 に答える
0

GenerationType.Auto.Try it.I を使用しないでください。同じ事例はこちら

于 2012-05-09T09:16:54.277 に答える