Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java.lang.AssertionError:org.hibernate.exception.sqlgrammareexception:无法插入:_Java_Mysql_Spring_Hibernate_Jpa - Fatal编程技术网

java.lang.AssertionError:org.hibernate.exception.sqlgrammareexception:无法插入:

java.lang.AssertionError:org.hibernate.exception.sqlgrammareexception:无法插入:,java,mysql,spring,hibernate,jpa,Java,Mysql,Spring,Hibernate,Jpa,我在我的项目中使用Spring Mvc Jpa mysql。 我的依赖项有一些问题需要解决,我有义务创建一个新项目,并将旧项目中的代码与其他依赖项一起复制。第一次我忘记了make create in: <property name="hibernate.hbm2ddl.auto" value="update"/> 特殊等级: 包com.pattern.learning.entites import java.io.Serializable;

我在我的项目中使用Spring Mvc Jpa mysql。 我的依赖项有一些问题需要解决,我有义务创建一个新项目,并将旧项目中的代码与其他依赖项一起复制。第一次我忘记了make create in:

             <property name="hibernate.hbm2ddl.auto" value="update"/> 
特殊等级: 包com.pattern.learning.entites

     import java.io.Serializable;
     import java.util.Collection;

     import javax.persistence.Entity;
     import javax.persistence.GeneratedValue;
     import javax.persistence.GenerationType;
     import javax.persistence.Id;
     import javax.persistence.JoinColumn;
     import javax.persistence.JoinTable;
     import javax.persistence.ManyToMany;
     import javax.persistence.OneToMany;
     import javax.persistence.Table;
     @Entity
        @Table(name="Specialite")
  public class Specialite implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
 private Long idspeciality;
 private String nomspecialite;
 private String desciption;
 private byte[]  photo;
 private String nomphoto;
 @OneToMany(mappedBy="specialite")
 private Collection<Cours> cours;
 @ManyToMany
@JoinTable(
        name="Spe_user",joinColumns= 
       @JoinColumn(name="idspeciality"),
      inverseJoinColumns=@JoinColumn(name="iduser"))
 private Collection<User> users;
 @OneToMany(mappedBy="specialite")
 private Collection<Competance> competances;

public Collection<Competance> getCompetances() {
    return competances;
}
public void setCompetances(Collection<Competance> competances) {
    this.competances = competances;
}
public Long getIdspeciality() {
    return idspeciality;
}
public void setIdspeciality(Long idspeciality) {
    this.idspeciality = idspeciality;
}
public String getNomspecialite() {
    return nomspecialite;
}
public void setNomspecialite(String nomspecialite) {
    this.nomspecialite = nomspecialite;
}
public String getDesciption() {
    return desciption;
}
public void setDesciption(String desciption) {
    this.desciption = desciption;
}
public byte[] getPhoto() {
    return photo;
}
public void setPhoto(byte[] photo) {
    this.photo = photo;
}
public String getNomphoto() {
    return nomphoto;
}
public void setNomphoto(String nomphoto) {
    this.nomphoto = nomphoto;
}
public Collection<Cours> getCours() {
    return cours;
}
public void setCours(Collection<Cours> cours) {
    this.cours = cours;
}
public Collection<User> getUsers() {
    return users;
}
public void setUsers(Collection<User> users) {
    this.users = users;
}
public Specialite(String nomspecialite, String desciption, byte[] photo,
        String nomphoto) {
    super();
    this.nomspecialite = nomspecialite;
    this.desciption = desciption;
    this.photo = photo;
    this.nomphoto = nomphoto;
}
public Specialite() {
    super();
    // TODO Auto-generated constructor stub
}



 }
import java.io.Serializable;
导入java.util.Collection;
导入javax.persistence.Entity;
导入javax.persistence.GeneratedValue;
导入javax.persistence.GenerationType;
导入javax.persistence.Id;
导入javax.persistence.JoinColumn;
导入javax.persistence.JoinTable;
导入javax.persistence.ManyToMany;
导入javax.persistence.OneToMany;
导入javax.persistence.Table;
@实体
@表(name=“Specialite”)
公共类Specialite实现了可序列化{
@身份证
@GeneratedValue(策略=GenerationType.IDENTITY)
私人长期专业;
私有字符串;
私有字符串描述;
私有字节[]照片;
私人照片;
@OneToMany(mappedBy=“specialite”)
私人收藏课程;
@许多
@可接合(
name=“Spe_user”,joinColumns=
@JoinColumn(name=“idspeciality”),
inverseJoinColumns=@JoinColumn(name=“iduser”))
私人收藏用户;
@OneToMany(mappedBy=“specialite”)
私人收藏比赛;
公开募捐{
回报竞争;
}
公开募捐竞赛(募捐竞赛){
这个。竞争=竞争;
}
公共长getIdspeciality(){
返回idspeciality;
}
public void setIdspeciality(长idspeciality){
this.idspeciality=idspeciality;
}
公共字符串getNomspecialite(){
返回nomlite;
}
public void setNomspecialite(字符串nomspecialite){
this.nomspecialite=nomspecialite;
}
公共字符串getdescription(){
返回描述;
}
公共无效设置说明(字符串说明){
this.description=描述;
}
公共字节[]getPhoto(){
返回照片;
}
公共无效设置照片(字节[]照片){
this.photo=照片;
}
公共字符串getNomphoto(){
返回照片;
}
公共无效setNomphoto(字符串nomphoto){
this.nomphoto=nomphoto;
}
公共收藏getCours(){
返程;
}
公共无效设置课程(收集课程){
this.cours=cours;
}
公共集合getUsers(){
返回用户;
}
公共void集合用户(集合用户){
this.users=用户;
}
public Specialite(字符串nomsspecialite,字符串描述,字节[]照片,
(照片){
超级();
this.nomspecialite=nomspecialite;
this.description=描述;
this.photo=照片;
this.nomphoto=nomphoto;
}
公共专用软件(){
超级();
//TODO自动生成的构造函数存根
}
}

我真的需要你的帮助

看来你还没有在
persistence.xml中指定实体类

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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://xmlns.jcp.org/xml/ns/persistence/persistence_2_0.xsd ">
  <persistence-unit name="UP_LR" transaction-type="RESOURCE_LOCAL">

     <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>com.pattern.learning.entites.Specialite</class>
        <class>com.pattern.learning.entites.Entity1</class>
        <class>com.pattern.learning.entites.Entity1</class>

        <properties>
           <property name="hibernate.show_sql" value="true"/>
           <property name="hibernate.hbm2ddl.auto" value="update"/>
           <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        </properties>

 </persistence-unit>

org.hibernate.ejb.HibernatePersistence
com.pattern.learning.entites.Specialite
com.pattern.learning.entites.Entity1
com.pattern.learning.entites.Entity1


希望这有帮助。

在OP中发布您的DTO。Hibernate无法正确写入您的表,您可能在映射上有一些问题。specialite class@JasonZI能够使用相同的代码插入iv刚刚将我的数据库更改为新数据库我发现了它我忘记添加spring core依赖项。谢谢你的帮助help@KaoutarLaz:您在哪里指定了实体类?不在persistence.xml中?我在applicationContext.xml中指定了这一点
       javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not insert: [com.pattern.learning.entites.Specialite]
org.hibernate.ejb.AbstractEntityManagerImpl.throwPersistenceException(AbstractEntityManagerImpl.java:630)
org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:219)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
com.sun.proxy.$Proxy23.persist(Unknown Source)
com.pattern.learning.dao.ElearningDaoImpl.ajouterSpecialite(ElearningDaoImpl.java:19)
com.pattern.learning.metier.LearningMetierImp.ajouterSpecialite(LearningMetierImp.java:67)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
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)
com.sun.proxy.$Proxy25.ajouterSpecialite(Unknown Source)
com.pattern.learning.controller.AdminSpecialiteController.saveSpe(AdminSpecialiteController.java:55)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
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.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

     cause mère 

   org.hibernate.exception.SQLGrammarException: could not insert: [com.pattern.learning.entites.Specialite]
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:40)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2158)
org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2638)
org.hibernate.action.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:48)
org.hibernate.engine.ActionQueue.execute(ActionQueue.java:250)
org.hibernate.event.def.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:298)
org.hibernate.event.def.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:181)
org.hibernate.event.def.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:107)
org.hibernate.ejb.event.EJB3PersistEventListener.saveWithGeneratedId(EJB3PersistEventListener.java:49)
org.hibernate.event.def.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:131)
org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:87)
org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:38)
org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:618)
org.hibernate.impl.SessionImpl.persist(SessionImpl.java:592)
org.hibernate.impl.SessionImpl.persist(SessionImpl.java:596)
org.hibernate.ejb.AbstractEntityManagerImpl.persist(AbstractEntityManagerImpl.java:213)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:240)
com.sun.proxy.$Proxy23.persist(Unknown Source)
com.pattern.learning.dao.ElearningDaoImpl.ajouterSpecialite(ElearningDaoImpl.java:19)
com.pattern.learning.metier.LearningMetierImp.ajouterSpecialite(LearningMetierImp.java:67)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
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)
com.sun.proxy.$Proxy25.ajouterSpecialite(Unknown Source)
com.pattern.learning.controller.AdminSpecialiteController.saveSpe(AdminSpecialiteController.java:55)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
java.lang.reflect.Method.invoke(Method.java:606)
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.doPost(FrameworkServlet.java:789)
javax.servlet.http.HttpServlet.service(HttpServlet.java:650)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
     import java.io.Serializable;
     import java.util.Collection;

     import javax.persistence.Entity;
     import javax.persistence.GeneratedValue;
     import javax.persistence.GenerationType;
     import javax.persistence.Id;
     import javax.persistence.JoinColumn;
     import javax.persistence.JoinTable;
     import javax.persistence.ManyToMany;
     import javax.persistence.OneToMany;
     import javax.persistence.Table;
     @Entity
        @Table(name="Specialite")
  public class Specialite implements Serializable {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
 private Long idspeciality;
 private String nomspecialite;
 private String desciption;
 private byte[]  photo;
 private String nomphoto;
 @OneToMany(mappedBy="specialite")
 private Collection<Cours> cours;
 @ManyToMany
@JoinTable(
        name="Spe_user",joinColumns= 
       @JoinColumn(name="idspeciality"),
      inverseJoinColumns=@JoinColumn(name="iduser"))
 private Collection<User> users;
 @OneToMany(mappedBy="specialite")
 private Collection<Competance> competances;

public Collection<Competance> getCompetances() {
    return competances;
}
public void setCompetances(Collection<Competance> competances) {
    this.competances = competances;
}
public Long getIdspeciality() {
    return idspeciality;
}
public void setIdspeciality(Long idspeciality) {
    this.idspeciality = idspeciality;
}
public String getNomspecialite() {
    return nomspecialite;
}
public void setNomspecialite(String nomspecialite) {
    this.nomspecialite = nomspecialite;
}
public String getDesciption() {
    return desciption;
}
public void setDesciption(String desciption) {
    this.desciption = desciption;
}
public byte[] getPhoto() {
    return photo;
}
public void setPhoto(byte[] photo) {
    this.photo = photo;
}
public String getNomphoto() {
    return nomphoto;
}
public void setNomphoto(String nomphoto) {
    this.nomphoto = nomphoto;
}
public Collection<Cours> getCours() {
    return cours;
}
public void setCours(Collection<Cours> cours) {
    this.cours = cours;
}
public Collection<User> getUsers() {
    return users;
}
public void setUsers(Collection<User> users) {
    this.users = users;
}
public Specialite(String nomspecialite, String desciption, byte[] photo,
        String nomphoto) {
    super();
    this.nomspecialite = nomspecialite;
    this.desciption = desciption;
    this.photo = photo;
    this.nomphoto = nomphoto;
}
public Specialite() {
    super();
    // TODO Auto-generated constructor stub
}



 }
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.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://xmlns.jcp.org/xml/ns/persistence/persistence_2_0.xsd ">
  <persistence-unit name="UP_LR" transaction-type="RESOURCE_LOCAL">

     <provider>org.hibernate.ejb.HibernatePersistence</provider>

        <class>com.pattern.learning.entites.Specialite</class>
        <class>com.pattern.learning.entites.Entity1</class>
        <class>com.pattern.learning.entites.Entity1</class>

        <properties>
           <property name="hibernate.show_sql" value="true"/>
           <property name="hibernate.hbm2ddl.auto" value="update"/>
           <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
        </properties>

 </persistence-unit>