java - Hibernate (on postgres) dropping Schema from @JoinTable -


i'm using hibernate 4.3.10.final (with springdata jpa) running on postgres 4 database , have run strange bug. our app utilizes database outside of default "public" schema, , when try insert data hibernate drops correct schema.

our model consists of abstract "log" class uses single class inheritance allow many different object types insert associated log message. see code below.

the schema exists (hibernate doesn't create it) , booting validation runs fine, when try insert new record error relation "booking_log" not exist -- missing schema modifier (say customapp our purposes). see first line logs below idea of other insert statements like.

i've dug through mapping phase , verified hibernate indeed picking schema @jointable annotation, not sure how we're losing it.

any debugging or possible solutions appreciated.

thanks!


log - abstract super class

@mappedsuperclass @table(name="log", schema=constants.db_schema) @inheritance(strategy=inheritancetype.single_table) @discriminatorcolumn(name="log_type_id", discriminatortype = discriminatortype.integer) public abstract class log {      @id     @generatedvalue(strategy=generationtype.sequence, generator="log_seq_gen")     @sequencegenerator(allocationsize = 1, name="log_seq_gen", sequencename=constants.db_schema + ".log_id_seq")     private long id;      // ...       } 

bookinglog

@entity @discriminatorvalue("2") public class bookinglog extends log implements tenantresource<company,long> {      @jointable(name="booking_log",         schema = constants.db_schema,         joincolumns = { @joincolumn(name="log_id", referencedcolumnname="id", nullable=false, updatable=false)},         inversejoincolumns = { @joincolumn(name="booking_id", referencedcolumnname="id", nullable=false, updatable=false)})     @manytoone(cascade=cascadetype.all)     private booking booking;      ///...       } 

** logs **

2015-07-20_18:14:09.055 debug org.hibernate.sql - insert customapp.booking_product (created_dt, created_by, modified_dt, modified_by, include_in_payroll, include_in_revenue, booking_id, description, payroll_percent, price, product_id, qty, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 2015-07-20_18:14:09.072 debug org.hibernate.sql - insert booking_log (log_date, details, log_time, user_id, booking_id, id) values (?, ?, ?, ?, ?, ?) 2015-07-20_18:14:09.176 debug o.h.e.jdbc.spi.sqlexceptionhelper - not execute statement [n/a] org.postgresql.util.psqlexception: error: relation "booking_log" not exist 

based on @jointable configuration , insert statement hibernate generates looks problem way triyng add fields/data booking_log table.

i need more details model sure think using join-table , else instead of create class models join-table.

i mean, have this

bookinglog (*) --------------------------------------> (1) booking 

but think need this

bookinglog (1) ---> (1) bookinglogassociation (*) ---> (1) booking 

then mapping this,

@entity @discriminatorvalue("2") public class bookinglog extends log implements tenantresource<company,long> {    @onetoone(mappedby="bookinglog")   private bookinglogassociation booking;  } 

note attributes of bookinglogassociation, field/data want add in booking_log table.

@entity @table(name="booking_log") @idclass(bookinglogassociationid.class) public class bookinglogassociation {    @id   private long log_id;   @id   private long booking_id;    @onetoone   @primarykeyjoincolumn(name="log_id", referencedcolumnname="id")   private bookinglog bookinglog;    @manytoone   @primarykeyjoincolumn(name="booking_id", referencedcolumnname="id")   private booking booking;    @column(name="log_date")   @temporal(temporaltype.date)   private calendar logdate;    @column(name="log_time")   @temporal(temporaltype.time)   private calendar logtime;    @manytoone   @joincolumn(name="user_id")   private user user;   // attribute   //@column(name="user_id")   //private long userid;   ... } 

the bookinglogassociationid class represents bookinglogassociation's composite key.

public class bookinglogassociationid implements serializable {    private long log_id;    private long booking_id;    public int hashcode() {     return (int)(log_id + booking_id);   }    public boolean equals(object object) {     if (object instanceof bookinglogassociationid) {       bookinglogassociationid otherid = (bookinglogassociationid) object;       return (otherid.log_id == this.log_id) && (otherid.booking_id == this.booking_id);     }     return false;   } 

you can read more option here


Comments