Java Hibernate@ManyToMany,错误:关系不存在
我试图实现与两个实体的多对多关系:书籍和作者 一本书可以由多个作者撰写,并且作者可以撰写多本书 但当我试图坚持一本书的作者,我得到了一个错误:关系“书”不存在 下面是更多的信息:Java Hibernate@ManyToMany,错误:关系不存在,java,postgresql,hibernate,jpa,java-ee-8,Java,Postgresql,Hibernate,Jpa,Java Ee 8,我试图实现与两个实体的多对多关系:书籍和作者 一本书可以由多个作者撰写,并且作者可以撰写多本书 但当我试图坚持一本书的作者,我得到了一个错误:关系“书”不存在 下面是更多的信息: 实体 账簿实体 package orm.model; import java.util.List; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.GeneratedValue;
实体 账簿实体
package orm.model;
import java.util.List;
import javax.persistence.Column;
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;
@Entity
public class Livre {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
@Column(name="livre_id")
Long livre_id;
@ManyToMany
@JoinTable(
name="livre_auteur",
joinColumns = {@JoinColumn(referencedColumnName = "livre_id")},
inverseJoinColumns = {@JoinColumn(referencedColumnName = "auteur_id")}
)
private List<Auteur> auteurs;
private String title;
public Livre() {
}
public Long getLivre_id() {
return livre_id;
}
public void setLivre_id(Long livre_id) {
this.livre_id = livre_id;
}
public List<Auteur> getAuteurs() {
return auteurs;
}
public void setAuteurs(List<Auteur> auteurs) {
this.auteurs = auteurs;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
}
作者道:
package orm.dao;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.TypedQuery;
import orm.exception.AlreadyExistsException;
import orm.helper.Helper;
import orm.model.Auteur;
public class AuteurDao extends GenericDao {
public Auteur insert(Auteur auteur) throws AlreadyExistsException {
EntityManager entityManager = getEntityManager();
//check if Auteur exists
Auteur existingAuteur = findById(auteur.getAuteur_id());
if(existingAuteur!=null) {
throw new AlreadyExistsException("l'auteur existe déjà dans la base de donnée, id : " + auteur.getAuteur_id());
}
Helper.beginTransaction(entityManager);
entityManager.persist(auteur);
Helper.commitTransactionAndClose(entityManager);
return auteur;
}
private Auteur findById(Long id) {
TypedQuery<Auteur> query = getEntityManager().createQuery("from Auteur a where a.auteur_id = :id", Auteur.class);
query.setParameter("id", id);
try {
return query.getSingleResult();
} catch (NoResultException e) {
return null;
}
}
}
包orm.dao;
导入javax.persistence.EntityManager;
导入javax.persistence.NoResultException;
导入javax.persistence.TypedQuery;
导入orm.exception.alreadyexistException;
导入orm.helper.helper;
导入orm.model.Auteur;
公共类AuteurDao扩展了GenericDao{
公共AUTUR insert(AUTUR AUTUR)抛出已存在的异常{
EntityManager EntityManager=getEntityManager();
//检查AUTUR是否存在
Auteur existingAuteur=findById(Auteur.getAuteur_id());
if(existingAuteur!=null){
抛出新的已经存在的性别概念(“存在于donnée基地的自我存在,id:+auteur.getAuteur_id());
}
Helper.beginTransaction(entityManager);
实体管理器(AUTUR);
Helper.CommitTransaction和Close(实体管理器);
回归导演;
}
私人导演findById(长id){
TypedQuery query=getEntityManager().createQuery(“来自Auteur a,其中a.Auteur\u id=:id”,Auteur.class);
query.setParameter(“id”,id);
试一试{
返回query.getSingleResult();
}捕获(noresulte异常){
返回null;
}
}
}
书刀:
package orm.dao;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import orm.exception.AlreadyExistsException;
import orm.helper.Helper;
import orm.model.Livre;
public class LivreDao extends GenericDao{
public Livre insert(Livre livre) throws AlreadyExistsException{
EntityManager entityManager = getEntityManager();
//test if livre already exist
Livre existingLivre = findByNumber(livre.getLivre_id());
if(existingLivre!=null) {
throw new AlreadyExistsException("livre already in database with id : " + livre.getLivre_id());
}
Helper.beginTransaction(entityManager);
entityManager.persist(livre);
Helper.commitTransactionAndClose(entityManager);
return livre;
}
private Livre findByNumber(Long id) {
TypedQuery<Livre> query = getEntityManager().createQuery("from Livre l where l.livre_id = :id", Livre.class);
query.setParameter("id", id);
try {
return query.getSingleResult();
} catch (Exception e) {
return null;
}
}
}
包orm.dao;
导入javax.persistence.EntityManager;
导入javax.persistence.TypedQuery;
导入orm.exception.alreadyexistException;
导入orm.helper.helper;
导入orm.model.Livre;
公共类LivreDao扩展了GenericDao{
公共Livre insert(Livre-Livre)抛出已存在的异常{
EntityManager EntityManager=getEntityManager();
//测试livre是否已经存在
Livre existingLivre=findByNumber(Livre.getLivre_id());
if(existingLivre!=null){
抛出新的AlreadyExistsException(“livre已经在数据库中,id为:+livre.getLivre_id());
}
Helper.beginTransaction(entityManager);
entityManager.persist(livre);
Helper.CommitTransaction和Close(实体管理器);
回归生活;
}
private Livre findByNumber(长id){
TypedQuery query=getEntityManager().createQuery(“来自Livre l,其中l.Livre_id=:id”,Livre.class);
query.setParameter(“id”,id);
试一试{
返回query.getSingleResult();
}捕获(例外e){
返回null;
}
}
}
主要
orm包;
导入java.util.ArrayList;
导入java.util.List;
导入orm.dao.LivreDao;
导入orm.exception.alreadyexistException;
导入orm.model.Auteur;
导入orm.model.Livre;
公共班机{
公共静态void main(字符串[]args)引发AlreadyExistsException{
//第一作者
AUTUR jSlater=新AUTUR();
jSlater.setName(“杰克”);
jSlater.setSurName(“Slater”);
//第二作者
Auteur jBegood=新的Auteur();
jBegood.setName(“Begood”);
jBegood.setSurName(“约翰尼”);
//作者名单
List auteurs=new ArrayList();
添加(稍后);
添加(jBegood);
//书
Livre Livre=新Livre();
//将多个作者设置为book
livre.setTitle(“la chèvre enchantée”);
livre.setAuteurs(auteurs);
//创建Livre列表
List livreList1=new ArrayList();
livreList1.添加(livre);
List livreList2=new ArrayList();
livreList2.添加(livre);
//填充到以前创建的Actors
jSlater.setLivres(livreList1);
jBegood.setLivres(livreList2);
//然后保存
LivreDao LivreDao=新的LivreDao();
livreDao.插入(livre);
}
}
错误堆栈跟踪:
avr. 18, 2019 7:59:30 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: entrainement
...]
avr. 18, 2019 7:59:30 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.12.Final}
avr. 18, 2019 7:59:30 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
avr. 18, 2019 7:59:30 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
avr. 18, 2019 7:59:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
avr. 18, 2019 7:59:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/entrainement-orm]
avr. 18, 2019 7:59:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=postgres, password=****}
avr. 18, 2019 7:59:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
avr. 18, 2019 7:59:30 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
avr. 18, 2019 7:59:30 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL81Dialect
avr. 18, 2019 7:59:31 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
avr. 18, 2019 7:59:32 PM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory
avr. 18, 2019 7:59:32 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42P01
avr. 18, 2019 7:59:32 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERREUR: la relation « livre » n'existe pas
Position : 74
avr. 18, 2019 7:59:32 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42P01
avr. 18, 2019 7:59:32 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERREUR: la relation « livre » n'existe pas
Position : 13
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:149)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:789)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:767)
at orm.dao.LivreDao.insert(LivreDao.java:24)
at orm.Main.main(Main.java:32)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:178)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:45)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2919)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3490)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:626)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:280)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:261)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:306)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:318)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:275)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:113)
at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:67)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:782)
... 3 more
Caused by: org.postgresql.util.PSQLException: ERREUR: la relation « livre » n'existe pas
Position : 13
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:562)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:366)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:175)
... 20 more
avr。2019年7月18日下午7:59:30 org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
信息:HH000204:正在处理PersistenceUnitInfo[
名称:夹带
...]
avr。2019年7月18日下午7:59:30 org.hibernate.Version日志版本
信息:hh000412:Hibernate核心{5.2.12.Final}
avr。2019年7月18日下午7:59:30 org.hibernate.cfg.Environment
信息:HH000206:找不到hibernate.properties
avr。2019年7月18日下午7:59:30 org.hibernate.annotations.common.reflection.java.JavaReflectionManager
信息:HCANN000001:Hibernate Commons注释{5.0.1.Final}
avr。2019年7月18日下午7:59:30 org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
警告:HHH10001002:使用Hibernate内置连接池(不用于生产!)
avr。2019年7月18日下午7:59:30 org.hibernate.engine.jdbc.connections.internal.driverManager连接提供者MPL buildCreator
信息:HHH10001005:在URL[jdbc:p]处使用驱动程序[org.postgresql.driver]ostgresql://localhost:5432/entrainement-orm]
avr。2019年7月18日下午7:59:30 org.hibernate.engine.jdbc.connections.internal.driverManager连接提供者MPL buildCreator
信息:HHH10001001:连接属性:{user=postgres,password=**}
avr。2019年7月18日下午7:59:30 org.hibernate.engine.jdbc.connections.internal.driverManager连接提供者MPL buildCreator
信息:HHH10001003:自动提交模式:错误
avr。2019年7月18日下午7:59:30 org.hibernate.engine.jdbc.connections.internal.PooledConnections
信息:HH000115:休眠连接池大小:20(最小值=1)
avr。2019年7月18日下午7:59:30 org.hibernate.dialogue.dialogue
信息:HH000400:使用方言:org.hibernate.dialogue.postgresql81dialogue
avr。2019年7月18日下午7:59:31 org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl UseContexturalAllobCreation
信息:HH000424:当createClob()方法引发错误时禁用上下文LOB创建:java.lang.reflect.InvocationTargetException
avr。18, 2019 7:
package orm.dao;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;
import orm.exception.AlreadyExistsException;
import orm.helper.Helper;
import orm.model.Livre;
public class LivreDao extends GenericDao{
public Livre insert(Livre livre) throws AlreadyExistsException{
EntityManager entityManager = getEntityManager();
//test if livre already exist
Livre existingLivre = findByNumber(livre.getLivre_id());
if(existingLivre!=null) {
throw new AlreadyExistsException("livre already in database with id : " + livre.getLivre_id());
}
Helper.beginTransaction(entityManager);
entityManager.persist(livre);
Helper.commitTransactionAndClose(entityManager);
return livre;
}
private Livre findByNumber(Long id) {
TypedQuery<Livre> query = getEntityManager().createQuery("from Livre l where l.livre_id = :id", Livre.class);
query.setParameter("id", id);
try {
return query.getSingleResult();
} catch (Exception e) {
return null;
}
}
}
package orm;
import java.util.ArrayList;
import java.util.List;
import orm.dao.LivreDao;
import orm.exception.AlreadyExistsException;
import orm.model.Auteur;
import orm.model.Livre;
public class Main {
public static void main(String[] args) throws AlreadyExistsException {
//1st author
Auteur jSlater = new Auteur();
jSlater.setName("Jack");
jSlater.setSurName("Slater");
//2nd author
Auteur jBegood = new Auteur();
jBegood.setName("Begood");
jBegood.setSurName("Johnny");
//author list
List<Auteur> auteurs = new ArrayList<Auteur>();
auteurs.add(jSlater);
auteurs.add(jBegood);
//book
Livre livre = new Livre();
//set multiple authors to book
livre.setTitle("la chèvre enchantée");
livre.setAuteurs(auteurs);
// create Livre lists
List<Livre> livreList1 = new ArrayList<>();
livreList1.add(livre);
List<Livre> livreList2 = new ArrayList<>();
livreList2.add(livre);
// populate to previously created Acteurs
jSlater.setLivres(livreList1);
jBegood.setLivres(livreList2);
// then save
LivreDao livreDao = new LivreDao();
livreDao.insert(livre);
}
}
avr. 18, 2019 7:59:30 PM org.hibernate.jpa.internal.util.LogHelper logPersistenceUnitInformation
INFO: HHH000204: Processing PersistenceUnitInfo [
name: entrainement
...]
avr. 18, 2019 7:59:30 PM org.hibernate.Version logVersion
INFO: HHH000412: Hibernate Core {5.2.12.Final}
avr. 18, 2019 7:59:30 PM org.hibernate.cfg.Environment <clinit>
INFO: HHH000206: hibernate.properties not found
avr. 18, 2019 7:59:30 PM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
INFO: HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
avr. 18, 2019 7:59:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl configure
WARN: HHH10001002: Using Hibernate built-in connection pool (not for production use!)
avr. 18, 2019 7:59:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001005: using driver [org.postgresql.Driver] at URL [jdbc:postgresql://localhost:5432/entrainement-orm]
avr. 18, 2019 7:59:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001001: Connection properties: {user=postgres, password=****}
avr. 18, 2019 7:59:30 PM org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl buildCreator
INFO: HHH10001003: Autocommit mode: false
avr. 18, 2019 7:59:30 PM org.hibernate.engine.jdbc.connections.internal.PooledConnections <init>
INFO: HHH000115: Hibernate connection pool size: 20 (min=1)
avr. 18, 2019 7:59:30 PM org.hibernate.dialect.Dialect <init>
INFO: HHH000400: Using dialect: org.hibernate.dialect.PostgreSQL81Dialect
avr. 18, 2019 7:59:31 PM org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl useContextualLobCreation
INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
avr. 18, 2019 7:59:32 PM org.hibernate.hql.internal.QueryTranslatorFactoryInitiator initiateService
INFO: HHH000397: Using ASTQueryTranslatorFactory
avr. 18, 2019 7:59:32 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42P01
avr. 18, 2019 7:59:32 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERREUR: la relation « livre » n'existe pas
Position : 74
avr. 18, 2019 7:59:32 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
WARN: SQL Error: 0, SQLState: 42P01
avr. 18, 2019 7:59:32 PM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
ERROR: ERREUR: la relation « livre » n'existe pas
Position : 13
Exception in thread "main" javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:149)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:157)
at org.hibernate.internal.ExceptionConverterImpl.convert(ExceptionConverterImpl.java:164)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:789)
at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:767)
at orm.dao.LivreDao.insert(LivreDao.java:24)
at orm.Main.main(Main.java:32)
Caused by: org.hibernate.exception.SQLGrammarException: could not execute statement
at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:106)
at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:42)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:111)
at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:97)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:178)
at org.hibernate.id.insert.AbstractSelectingDelegate.performInsert(AbstractSelectingDelegate.java:45)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2919)
at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3490)
at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:626)
at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:280)
at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:261)
at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:306)
at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:318)
at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:275)
at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:182)
at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:113)
at org.hibernate.jpa.event.internal.core.JpaPersistEventListener.saveWithGeneratedId(JpaPersistEventListener.java:67)
at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:189)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:132)
at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:58)
at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:782)
... 3 more
Caused by: org.postgresql.util.PSQLException: ERREUR: la relation « livre » n'existe pas
Position : 13
at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2198)
at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1927)
at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:255)
at org.postgresql.jdbc2.AbstractJdbc2Statement.execute(AbstractJdbc2Statement.java:562)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeWithFlags(AbstractJdbc2Statement.java:420)
at org.postgresql.jdbc2.AbstractJdbc2Statement.executeUpdate(AbstractJdbc2Statement.java:366)
at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:175)
... 20 more
//book
Livre livre = new Livre();
//set multiple authors to book
livre.setAuteurs(auteurs);
livre.setTitle("la chèvre enchantée");
// create Livre lists
List<Livre> livreList1 = new ArrayList<>();
livreList1.add(livre);
List<Livre> livreList2 = new ArrayList<>();
livreList2.add(livre);
// populate to previously created Acteurs
jSlater.setLivres(livreList1);
jBegood.setLivres(livreList2);
// then save
LivreDao livreDao = new LivreDao();
livreDao.insert(livre);
@ManyToMany
@JoinTable(
name="**schemaName**.livre_auteur",
joinColumns = {@JoinColumn(referencedColumnName = "livre_id")},
inverseJoinColumns = {@JoinColumn(referencedColumnName = "auteur_id")}
)
private List<Auteur> auteurs;