[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - an interesting Hibernate / JPA Composite Key Question

cfrostrun do-not-reply at jboss.com
Thu Jul 24 23:15:24 EDT 2008


I was wondering if anybody had a good way to solve this... I have it semi-working, but the join columns are read only? is there anyway to get the join columns insertable/updateable?

Say I have 3 tables called TableA, TableB, TableC

Table A & Table B are basic 3 column composite primary key... Say id, globalId, and globalProfile.

table a(
id int not null,
global_id int not null,
global_profile varchar(50)
)

table b(
id int not null,
global_id int not null,
global_profile varchar(50)
)

TableC also has a 3 column composite primary key id, globalId, and globalProfile, however there's also foreign keys to table A & table B which reuse 2 of the 3 columns in the primary key for the foreign key to each table.

table c(
id int not null,
table_a_id int not null,
table_b_id int not null,
global_id int not null,
global_profile varchar(50)
)

so table c(table_a_id, global_id, global_profile) maps to table a(id, global_id, global_profile)

so table c(table_b_id, global_id, global_profile) maps to table b(id, global_id, global_profile)

I'm using.... 
	@ManyToOne
	@JoinColumns({
		@JoinColumn(name="table_a_id", referencedColumnName="id",insertable=false, updatable=false),	
		@JoinColumn(name="global_id", referencedColumnName="global_id", insertable=false, updatable=false),
		@JoinColumn(name="global_profile", referencedColumnName="global_profile", insertable=false, updatable=false)
	})

	@ManyToOne
	@JoinColumns({
		@JoinColumn(name="table_b_id", referencedColumnName="id", insertable=false, updatable=false),
		@JoinColumn(name="global_id", referencedColumnName="global_id", insertable=false, updatable=false),
		@JoinColumn(name="global_profile", referencedColumnName="global_profile", insertable=false, updatable=false)
	})	

So anybody have any good ways to create mutable data... if i remove the insertable/updatable i get an exception about mixing modes.  if i remove it across all elements i get sorry can't repeat columns in definition or something...

I understand this is a highly abnormal configuration, but the application requirements require this type of configuration since it's highly distributed data, that's also synchronizable across to a central location, and it needs to be able to co-exist.

so anybody have any ideas on how best to make it have a mutable configuration settings?  The other option is leave it read only .. . then anytime i need to mutate it just do that in straight jdbc??

Thanks for the ideas... 



View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4166550#4166550

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4166550



More information about the jboss-user mailing list