1
I want to create a relationship @OneToMany
in JPA using 3 tables I have already created in my database (I don’t want it to create the tables for me), the tables are Usuario
, Perfil
and UsuarioPerfil
. for this I am using the following code snippet in my User class.
@OneToMany(fetch = FetchType.EAGER)
List<Perfil> perfisPermitidos = new ArrayList<Perfil>();
The problem is when running the code the following Exception is launched
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table
'nomedomeubanco.Usuario_Perfil' doesn't exist
I know he does this because JPA tries to create the User_profile table automatically to use as an intermediate table, but I want him to use my table UsuarioPerfil
which already exists in my bank for exactly that purpose.
So that being said my question is how do JPA map the table UsuarioPerfil
as relationship table and do not try to create a default table which in this case is the table Usuario_Perfil
?
In order not to create the tables you have to put ddl-auto=None and create the tables manually or in some other way, using liquibase for example. About relationships see https://answall.com/a/234768/113075 this answer is very well made
– rnd_rss