当前位置: 首页 > 知识库问答 >
问题:

Eclipselink和Spring 3.1

澹台博文
2023-03-14

我可以使用Hibernate,但我正在尝试更改为Eclipselink。我一直在寻找解决办法,但没有结果。人们建议把这两个(不是放在一起)

<class>no.mesta.driftslogg.model.Person</class>  
<exclude-unlisted-classes>false</exclude-unlisted-classes>

persitence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/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_1_0.xsd">

<persistence-unit name="cccPersistenceUnit">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <exclude-unlisted-classes>false</exclude-unlisted-classes>
    <properties>
        <property name="eclipselink.ddl-generation" value="create-tables" />
        <property name="eclipselink.ddl-generation.output-mode" value="database" />
    </properties>
</persistence-unit>

应用程序-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"  xmlns:p="http://www.springframework.org/schema/p"
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">



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

<!-- JPA Hibernate shared entity manager -->
<bean id="entityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean" p:entityManagerFactory-ref="entityManagerFactory" /


<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">

    <property name="dataSource" ref="dataSource" />
    <property name="persistenceUnitName" value="cccPersistenceUnit" />
    <property name="jpaDialect" ref="jpaDialect" />
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.EclipseLinkJpaVendorAdapter">
        </bean>
    </property>
    <property name="loadTimeWeaver">
        <bean class="org.springframework.instrument.classloading.SimpleLoadTimeWeaver" />
    </property>
</bean>

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

<bean class="org.springframework.orm.jpa.support.PersistenceAnnotationBeanPostProcessor" />

<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    <property name="generateDdl" value="true" />
    <property name="databasePlatform" value="org.hibernate.dialect.MySQLDialect" />
    <!-- <property name="showSql" value="true" /> -->
</bean>



<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="com.mysql.jdbc.Driver" />
    <property name="jdbcUrl" value="jdbc:mysql://localhost:3306/driftslogg" />
    <property name="user" value="root" />
    <property name="password" value="root" />
    <property name="acquireIncrement" value="5" />
    <property name="idleConnectionTestPeriod" value="60" />
    <property name="maxPoolSize" value="100" />
    <property name="maxStatements" value="50" />
    <property name="minPoolSize" value="10" />
</bean>

package no.mesta.driftslogg.dao.jpa;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import no.mesta.driftslogg.dao.PersonDao;
import no.mesta.driftslogg.model.Person;

import org.springframework.stereotype.Repository;

@Repository
public class PersonDaoJpa implements PersonDao {

protected EntityManager entityManager;

@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
    this.entityManager = entityManager;
}

@Override
public Person save(Person person) {
    if (person.getId() != null) {
        return entityManager.merge(person);
    } else {
        entityManager.persist(person);
    }
    return person;
}

} 
package no.mesta.driftslogg.model;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

@Entity
public class Person {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;

public Long getId() {
    return id;
}

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

public String getName() {
    return name;
}

public void setName(String name) {
    this.name = name;
}

}

错误

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.IllegalArgumentException: Object: Todo [summary=This is a test, description=This is a test] is not a known entity type.
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:894)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
root cause

java.lang.IllegalArgumentException: Object: Todo [summary=This is a test, description=This is a test] is not a known entity type.
    org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.registerNewObjectForPersist(UnitOfWorkImpl.java:4169)
    org.eclipse.persistence.internal.jpa.EntityManagerImpl.persist(EntityManagerImpl.java:440)
    no.mesta.driftslogg.dao.jpa.PersonDaoJpa.save(PersonDaoJpa.java:45)
    no.mesta.driftslogg.service.impl.PersonServiceImpl.savePerson(PersonServiceImpl.java:20)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:318)
    org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
    org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
    org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:202)
    $Proxy15.savePerson(Unknown Source)
    no.mesta.driftslogg.controller.HomeController.home(HomeController.java:31)
    sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    java.lang.reflect.Method.invoke(Method.java:597)
    org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:212)
    org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:126)
    org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
    org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
    org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:900)
    org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:827)
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:621)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
    com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)

共有1个答案

弓胜泫
2023-03-14

您的错误发生在“TODO”对象上,而不是人。确保已映射所有相关对象。

您需要将no.mesta.driftslogg.model.person放在您的persistence.xml中,您没有这个。

 类似资料:
  • EclipseLink有可能和夸库斯一起使用吗?还是夸库斯太难与Hibernate耦合了? 我们正在选择我们的MP实现的过程中,我们希望尽可能接近参考信息 我在https://quarkus.io/guides/甚至这个论坛上都没有看到太多信息来表明eclipselink也可以与Quarkus一起使用。 任何关于夸库斯为什么与JPA的一个特定的impl(如果是的话)绑得如此紧密的指示也将是受欢迎的

  • 我正在将一个旧的IBM Process Server应用程序移植到IBM WebSphere Liberty。它包含大量基于服务数据对象(SDO)的代码。我有一些很好的工作代码,作为独立的Java运行,使用JDK8。我使用的是eclipselink 2.7.7,特别是两个jar文件; 我已经将此代码构建到一个Servlet中以处理SOAP请求,并将其与其他代码一起打包到一个EAR文件中,我将其部署

  • 使用带有规范和分页的Eclipse Link JPA 2.5.2,我对Oracle ROWNUM的执行方式有问题。Eclipse Link生成的查询如下: 为第一页运行该查询应返回0到25之间的行,为第二页运行相同的查询应返回25到50之间的行。 问题是第一页的记录也出现在第二页,我猜是因为submitteddate可以包含NULL值并且ORDER BY子句在ROWNUM和rnum条件或类似的东西

  • 问题内容: 我有一个问题,我无法解决。在hibernate状态下,我没有以下问题: 然后在我的schema.ddl中,我有这个: 这里没什么可看的。一切正常。但是,如果我将提供程序切换到EclipseLink,则会出现此错误: 因此,我当然会四处搜索,如果初始值为1且它应该等于分配大小,那么我会看到有关EclipseLink创建负数的一些信息。 因此,好的,因此添加“ initialValue =

  • Oracle 最近宣布把企业级的ORM平台TopLink代码捐献给Eclipse社区,发起并领导名为EclipseLink的Eclipse持久平台项目。 Eclipse持久平台由多个组件构成,主要有EclipseLink-ORM,EclipseLink-OXM,EclipseLink-SDO, EclipseLink-DAS,EclipseLink-DBWS,EclipseLink-XR,Ecli

  • 我在尝试解组对象时遇到了继承问题。这是我的班级 A. B C 容器 然后输入XML文件 我使用了EclipseLink JAXB与Spring OXM集成。当我将xml文件解组到容器实例时,所有内容都是重复的。在列表B中,我有两个重复的B实例(与列表C相同)。 请让我知道我做错了什么?谢谢你!