java - Spring Integration with Hibernate & JPA - one table not created on boot , others are -


i trying add 2 tables existing spring application. 1 being created in db , other not. cant see obvious differences jpa objects, , have updated db properties both. major difference between tables 1 mapped user's table in bi-direcitonal relationship, other one-directional.

here code samples:

persistence.xml:

<persistence-unit name="samplepersistenceunit" transaction-type="resource_local">    <provider>org.hibernate.ejb.hibernatepersistence</provider>     <class>com.bpc.services.domain.objects.user</class>     <class>com.bpc.services.domain.objects.account</class>     <class>com.bpc.services.domain.objects.transaction</class>     <class>com.bpc.services.domain.objects.payment</class>     <class>com.bpc.services.domain.objects.product</class>    <properties>        <!-- value="create" build new database on each run; value="update" modify existing database; value="create-drop" means same "create" drops tables when hibernate closes; value="validate" makes no changes database -->        <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.improvednamingstrategy"/>        <property name="hibernate.connection.charset" value="utf-8"/>        <property name="hbm2ddl.auto" value="update"/>        <property name="show_sql" value="true"/>        <property name="hibernate.hbm2ddl.auto" value="update"/>        <property name="hibernate.dialect" value="org.hibernate.dialect.mysql5dialect"/>    </properties> 

data-context.xml jpa declaration:

<jpa:repositories base-package="com.bpc.services.domain.repositories" /> 

product entity:

@entity @table(name = "product") public class product extends baseentity { 

payment entity:

@entity @table(name = "payment") public class payment extends baseentity {     @manytoone     user user; 

user entity:

@entity @table(name="rest_user") public class user extends baseentity {     @onetomany(mappedby="user",         targetentity=payment.class,         cascade= cascadetype.all)     @lazycollection(lazycollectionoption.false)     private list<payment> payments = new arraylist<payment>(); 

account entity:

@entity @table(name = "rest_account") public class account extends baseentity {     @manytoone     private product appliedproduct; 

product table has been created , , linked account object on *:1 relationship. payment table missing. deployment runs fine, , following shown in log:

[localhost-startstop-1] debug org.hibernate.cfg.ejb3column - binding column: ejb3column{table=org.hibernate.mapping.table(payment), mappingcolumn=id, insertable=true, updatable=true, unique=false}

so application knows payment domain object , using in deployment, when attempt use service via client log shows this:

debug o.h.e.jdbc.spi.sqlexceptionhelper - not extract resultset [n/a] com.mysql.jdbc.exceptions.jdbc4.mysqlsyntaxerrorexception: table 'services.payment' doesn't exist

[http-bio-8080-exec-3] warn o.h.e.jdbc.spi.sqlexceptionhelper - sql error: 1146, sqlstate: 42s02

[http-bio-8080-exec-3] error o.h.e.jdbc.spi.sqlexceptionhelper - table 'services.payment' doesn't exist


update tried running 'create' instead of 'update' (as suggested in answers) same issue. there additional log entry related payments table now:

11:37:14.994 [localhost-startstop-1] debug o.s.j.d.lazyconnectiondatasourceproxy - connecting database operation 'createstatement'

11:37:14.999 [localhost-startstop-1] debug org.hibernate.sql - alter table payment drop foreign key fk_5b79940uennr1ffusdus7cp2r

11:37:15.012 [localhost-startstop-1] error o.h.tool.hbm2ddl.schemaexport - hhh000389: unsuccessful: alter table payment drop foreign key fk_5b79940uennr1ffusdus7cp2r

11:37:15.012 [localhost-startstop-1] error o.h.tool.hbm2ddl.schemaexport - table 'services.payment' doesn't exist

11:37:15.012 [localhost-startstop-1] debug org.hibernate.sql - alter table rest_account drop foreign key fk_ek67yy1rmivvpoofrc0603du9

11:37:15.513 [localhost-startstop-1] debug org.hibernate.sql - alter table rest_verification_token drop foreign key fk_9i1lxa0i6h09fcobtm570hq7u

11:37:16.000 [localhost-startstop-1] debug org.hibernate.sql - alter table transactions drop foreign key fk_8i8qo3qvlyg4xaiqgrnbpfvvh

11:37:16.498 [localhost-startstop-1] debug org.hibernate.sql - alter table transactions drop foreign key fk_ce9ag0mlblwcp5n1bi1f2xwgs

11:37:16.993 [localhost-startstop-1] debug org.hibernate.sql - drop table if exists payment

when payment repository being loaded (without exceptions) shown in log:

identity insert: insert payment (time_created, uuid, version, description, in, out, performed_by, user, user_id) values (?, ?, ?, ?, ?, ?, ?, ?, ?)

11:37:14.919 [localhost-startstop-1] debug o.h.l.p.b.i.spaces.queryspacesimpl - adding queryspace : uid = -> org.hibernate.loader.plan.build.internal.spaces.entityqueryspaceimpl@b90c767]

11:37:14.923 [localhost-startstop-1] debug o.h.p.w.spi.metamodelgraphwalker - visiting attribute path : timecreated

11:37:14.923 [localhost-startstop-1] debug o.h.p.w.spi.metamodelgraphwalker - visiting attribute path : uuid

11:37:14.923 [localhost-startstop-1] debug o.h.p.w.spi.metamodelgraphwalker - visiting attribute path : version

11:37:14.923 [localhost-startstop-1] debug o.h.p.w.spi.metamodelgraphwalker - visiting attribute path : description

11:37:14.923 [localhost-startstop-1] debug o.h.p.w.spi.metamodelgraphwalker - visiting attribute path : in

11:37:14.923 [localhost-startstop-1] debug o.h.p.w.spi.metamodelgraphwalker - visiting attribute path : out

11:37:14.923 [localhost-startstop-1] debug o.h.p.w.spi.metamodelgraphwalker - visiting attribute path : performedby

11:37:14.923 [localhost-startstop-1] debug o.h.p.w.spi.metamodelgraphwalker - visiting attribute path : user

11:37:14.923 [localhost-startstop-1] debug o.h.l.p.b.i.spaces.queryspacesimpl - adding queryspace : uid = -> org.hibernate.loader.plan.build.internal.spaces.entityqueryspaceimpl@74febc11]

have tried <property name="hibernate.hbm2ddl.auto" value="create"/> instead of update? note create destroying previous data! see: doc details.


Comments

Popular posts from this blog

java - Date formats difference between yyyy-MM-dd'T'HH:mm:ss and yyyy-MM-dd'T'HH:mm:ssXXX -

c# - Get rid of xmlns attribute when adding node to existing xml -