@ManyToMany,Java持久化,未选择数据库

时间:2017-07-30 22:36:56

标签: java jpa many-to-many persist

我有一些实体。 产品和他的属性与单向@ManyToMany, 具有单向@ManyToOne的属性及其组(类别)。

我希望将新产品与其属性保持一致(合并)。 存在属性及其组(类别)。

但是当我尝试保存产品时,我选择了Exception No数据库。

当我保存产品时一切正常,但是当交易关闭时,我有这个例外。 当我剪切这段代码时,当我保存没有他的属性的产品时,一切都好。

enter image description here

这是我的产品实体:

@Entity
@Table(name = "PRODUCT", schema = "MYSHOP_SCHEMA")
public class ProductEntity implements Serializable {
    private long productId;
    private String productName;
    private int count;
    private double cost;
    private String size;
    private String battery;
    private String flyTime;
    private String distance;
    private String description;

    //private OrderEntity bucketByProductId;
    private ProductCategoryEntity productCategoryByCategory;

    private List<MultipartFile> images;
    private List<PicturesEntity> picturesByProductId;


    private Set<ProductPropertyEntity> properties = new HashSet<ProductPropertyEntity>();


    @Id
    @Column(name = "PRODUCT_ID")
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public long getProductId() {
        return productId;
    }

    public void setProductId(long productId) {
        this.productId = productId;
    }

    @Basic
    @Column(name = "NAME", nullable = false, length = 255)
    public String getProductName() {
        return productName;
    }

    public void setProductName(String productName) {
        this.productName = productName;
    }

    @Basic
    @Column(name = "COUNT", nullable = false)
    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    @Basic
    @Column(name = "COST", nullable = false)
    public double getCost() {
        return cost;
    }

    public void setCost(double cost) {
        this.cost = cost;
    }

    @Basic
    @Column(name = "SIZE")
    public String getSize() {
        return size;
    }

    public void setSize(String size) {
        this.size = size;
    }

    @Basic
    @Column(name = "BATTERY")
    public String getBattery() {
        return battery;
    }

    public void setBattery(String battery) {
        this.battery = battery;
    }

    @Basic
    @Column(name = "FLY_TIME")
    public String getFlyTime() {
        return flyTime;
    }

    public void setFlyTime(String flyTime) {
        this.flyTime = flyTime;
    }

    @Basic
    @Column(name = "DISTANCE")
    public String getDistance() {
        return distance;
    }

    public void setDistance(String distance) {
        this.distance = distance;
    }


    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ProductEntity)) return false;

        ProductEntity that = (ProductEntity) o;

        if (productId != that.productId) return false;
        if (count != that.count) return false;
        if (Double.compare(that.cost, cost) != 0) return false;
        if (size != that.size) return false;
        if (productName != null ? !productName.equals(that.productName) : that.productName != null) return false;
        if (battery != null ? !battery.equals(that.battery) : that.battery != null) return false;
        if (flyTime != null ? !flyTime.equals(that.flyTime) : that.flyTime != null) return false;
        return distance != null ? distance.equals(that.distance) : that.distance == null;
    }

    @Override
    public int hashCode() {
        int result;
        long temp;
        result = (int) (productId ^ (productId >>> 32));
        result = 31 * result + (productName != null ? productName.hashCode() : 0);
        result = 31 * result + count;
        temp = Double.doubleToLongBits(cost);
        result = 31 * result + (int) (temp ^ (temp >>> 32));
        result = 31 * result + (size != null ? size.hashCode() : 0);
        result = 31 * result + (battery != null ? battery.hashCode() : 0);
        result = 31 * result + (flyTime != null ? flyTime.hashCode() : 0);
        result = 31 * result + (distance != null ? distance.hashCode() : 0);
        return result;
    }


    @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
    @JoinColumn(name = "PRODUCT_ID", referencedColumnName = "PRODUCT_ID")
    public List<PicturesEntity> getPicturesByProductId() {
        return picturesByProductId;
    }

    public void setPicturesByProductId(List<PicturesEntity> picturesByProductId) {
        this.picturesByProductId = picturesByProductId;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "CATEGORY_ID", referencedColumnName = "CATEGORY_ID", nullable = false)
    public ProductCategoryEntity getProductCategoryByCategory() {
        return productCategoryByCategory;
    }

    public void setProductCategoryByCategory(ProductCategoryEntity productCategoryByCategory) {
        this.productCategoryByCategory = productCategoryByCategory;
    }


    //@ManyToMany(cascade = CascadeType.ALL)//, fetch = FetchType.EAGER)//(fetch = FetchType.LAZY)//(mappedBy = "product")
    //    @JoinTable(name = "Prod_Prop",
    //            joinColumns = @JoinColumn(name = "ProductId"),
    //            inverseJoinColumns = @JoinColumn(name = "ProductPropertyId"))
    @ManyToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "PRODUCT_HAS_PROPERTY",
            joinColumns = @JoinColumn(name = "PRODUCT_ID"),
            inverseJoinColumns = @JoinColumn(name = "PROPERTY_ID"))
    public Set<ProductPropertyEntity> getProperties() {
        return properties;
    }

    public void setProperties(Set<ProductPropertyEntity> properties) {
        this.properties = properties;
    }


    @Transient
    public List<MultipartFile> getImages() {
        return images;
    }

    public void setImages(List<MultipartFile> images) {
        this.images = images;
    }


    @Basic
    @Column(name = "Description")
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

}

这是我的房产实体:

@Entity
@Table(name = "PROPERTY", schema = "MYSHOP_SCHEMA")
public class ProductPropertyEntity implements Serializable {
    private int prodPropId;
    private String prodPropName;
    private PropertyCategoryEntity propertyCategoryByProdPropCatId;

    @Id
    @Column(name = "PROPERTY_ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getProdPropId() {
        return prodPropId;
    }

    public void setProdPropId(int prodPropId) {
        this.prodPropId = prodPropId;
    }

    @Basic
    @Column(name = "NAME", nullable = true, length = 255)
    public String getProdPropName() {
        return prodPropName;
    }

    public void setProdPropName(String prodPropName) {
        this.prodPropName = prodPropName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ProductPropertyEntity that = (ProductPropertyEntity) o;

        if (prodPropId != that.prodPropId) return false;
        if (prodPropName != null ? !prodPropName.equals(that.prodPropName) : that.prodPropName != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = prodPropId;
        result = 31 * result + (prodPropName != null ? prodPropName.hashCode() : 0);
        return result;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "PROPERTY_GROUP_ID")
    public PropertyCategoryEntity getPropertyCategoryByProdPropCatId() {
        return propertyCategoryByProdPropCatId;
    }

    public void setPropertyCategoryByProdPropCatId(PropertyCategoryEntity propertyCategoryByProdPropCatId) {
        this.propertyCategoryByProdPropCatId = propertyCategoryByProdPropCatId;
    }
}

这是我的类别属性实体:

@Entity
@Table(name = "PROPERTY_GROUP", schema = "MYSHOP_SCHEMA")
public class PropertyCategoryEntity implements Serializable {
    private int propCatId;
    private String propCatName;

    @Id
    @Column(name = "PROPERTY_GROUP_ID", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    public int getPropCatId() {
        return propCatId;
    }

    public void setPropCatId(int propCatId) {
        this.propCatId = propCatId;
    }

    @Basic
    @Column(name = "NAME", nullable = true, length = 255)
    public String getPropCatName() {
        return propCatName;
    }

    public void setPropCatName(String propCatName) {
        this.propCatName = propCatName;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        PropertyCategoryEntity that = (PropertyCategoryEntity) o;

        if (propCatId != that.propCatId) return false;
        if (propCatName != null ? !propCatName.equals(that.propCatName) : that.propCatName != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = propCatId;
        result = 31 * result + (propCatName != null ? propCatName.hashCode() : 0);
        return result;
    }

}

我通过这种方式保存产品:

@Override
public void addProduct(ProductEntity productEntity) {
    em.merge(productEntity);
   //em.flush();
}

然后我有例外:

> Message Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement

> Description The server encountered an unexpected condition that prevented it from fulfilling the request.

> Exception

> org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
       org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:982)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.jvschool.util.RoleFilter.doFilter(RoleFilter.java:31)

> Root Cause

> org.springframework.orm.jpa.JpaSystemException: could not execute statement; nested exception is org.hibernate.exception.GenericJDBCException: could not execute statement
        org.springframework.orm.jpa.vendor.HibernateJpaDialect.convertHibernateAccessException(HibernateJpaDialect.java:333)
    org.springframework.orm.jpa.vendor.HibernateJpaDialect.translateExceptionIfPossible(HibernateJpaDialect.java:244)
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:521)
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
    org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)
    org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
com.sun.proxy.$Proxy44.addProduct(Unknown Source)
com.jvschool.view.ManagerController.addProduct(ManagerController.java:105)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.jvschool.util.RoleFilter.doFilter(RoleFilter.java:31)
  

根本原因

     

org.hibernate.exception.GenericJDBCException:无法执行语句           org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)       org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)       org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)       org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207)       org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)       org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1301)       org.hibernate.action.internal.CollectionRecreateAction.execute(CollectionRecreateAction.java:50)       org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:447)       org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:333)       org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:335)       org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)       org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1224)       org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:464)       org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2894)       org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2270)       org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)       org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)       org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access $ 100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)       org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl $ TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:230)       org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)       org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:61)       org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)       org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)       org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)       org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)       org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)       org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)       org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)       org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)       com.sun.proxy。$ Proxy44.addProduct(未知来源)       com.jvschool.view.ManagerController.addProduct(ManagerController.java:105)       sun.reflect.NativeMethodAccessorImpl.invoke0(原生方法)       sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)       sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)       java.lang.reflect.Method.invoke(Method.java:498)       org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)       org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)       org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)       org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)       org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)       org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)       org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)       org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)       org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)       org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)       javax.servlet.http.HttpServlet.service(HttpServlet.java:661)       org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)       javax.servlet.http.HttpServlet.service(HttpServlet.java:742)       org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)       com.jvschool.util.RoleFilter.doFilter(RoleFilter.java:31)

> Root Cause

> java.sql.SQLException: No database selected
com.mysql.jdbc.SQLError.createSQLException(SQLError.java:996)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3887)
com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3823)
com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2435)
com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2582)
com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2530)
    com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1907)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2141)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2077)
com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2062)
net.sf.log4jdbc.PreparedStatementSpy.executeUpdate(PreparedStatementSpy.java:1021)
    org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
org.apache.commons.dbcp.DelegatingPreparedStatement.executeUpdate(DelegatingPreparedStatement.java:105)
org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:204)
org.hibernate.engine.jdbc.batch.internal.NonBatchingBatch.addToBatch(NonBatchingBatch.java:45)
org.hibernate.persister.collection.AbstractCollectionPersister.recreate(AbstractCollectionPersister.java:1301)
org.hibernate.action.internal.CollectionRecreateAction.execute(CollectionRecreateAction.java:50)
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:447)
org.hibernate.engine.spi.ActionQueue.executeActions(ActionQueue.java:333)
org.hibernate.event.internal.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:335)
org.hibernate.event.internal.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:39)
org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1224)
org.hibernate.internal.SessionImpl.managedFlush(SessionImpl.java:464)
org.hibernate.internal.SessionImpl.flushBeforeTransactionCompletion(SessionImpl.java:2894)
org.hibernate.internal.SessionImpl.beforeTransactionCompletion(SessionImpl.java:2270)
org.hibernate.engine.jdbc.internal.JdbcCoordinatorImpl.beforeTransactionCompletion(JdbcCoordinatorImpl.java:485)
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.beforeCompletionCallback(JdbcResourceLocalTransactionCoordinatorImpl.java:146)
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl.access$100(JdbcResourceLocalTransactionCoordinatorImpl.java:38)
org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.commit(JdbcResourceLocalTransactionCoordinatorImpl.java:230)
org.hibernate.engine.transaction.internal.TransactionImpl.commit(TransactionImpl.java:65)
org.hibernate.jpa.internal.TransactionImpl.commit(TransactionImpl.java:61)
org.springframework.orm.jpa.JpaTransactionManager.doCommit(JpaTransactionManager.java:517)
org.springframework.transaction.support.AbstractPlatformTransactionManager.processCommit(AbstractPlatformTransactionManager.java:761)
org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:730)
org.springframework.transaction.interceptor.TransactionAspectSupport.commitTransactionAfterReturning(TransactionAspectSupport.java:504)
org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:292)
org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)
com.sun.proxy.$Proxy44.addProduct(Unknown Source)
com.jvschool.view.ManagerController.addProduct(ManagerController.java:105)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:498)
org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
com.jvschool.util.RoleFilter.doFilter(RoleFilter.java:31)

新:

的persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>

<persistence-unit name="NewPersistenceUnit"/>

但是设置在dispatcher-servlet中:

<!-- Database Information -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
      destroy-method="close">
    <property name="driverClassName" value="net.sf.log4jdbc.DriverSpy"/>
    <property name="url" value="jdbc:log4jdbc:mysql://localhost:3306"/>
    <!--<property name="driverClassName" value="com.mysql.jdbc.Driver"/>-->
    <!--<property name="url" value="jdbc:mysql://localhost:3306/"/>-->
    <property name="username" value="root"/>
    <property name="password" value="password"/>
</bean>

<bean id="mms-persistence-unit" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="persistenceProviderClass" value="org.hibernate.jpa.HibernatePersistenceProvider"/>
    <property name="jpaVendorAdapter">
        <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
    </property>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.show_sql">true</prop>
            <!--<prop key="hibernate.format_sql">true</prop>-->

        </props>
    </property>
    <property name="packagesToScan">
        <list>
            <value>com.jvschool.entities</value>
        </list>
    </property>
</bean>

0 个答案:

没有答案