Two Laptop Bag
The moose likes Object Relational Mapping and the fly likes Dealing with Custom User Types as an Array in Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Object Relational Mapping
Reply Bookmark "Dealing with Custom User Types as an Array in Hibernate" Watch "Dealing with Custom User Types as an Array in Hibernate" New topic
Author

Dealing with Custom User Types as an Array in Hibernate

jai shreeram
Greenhorn

Joined: Apr 16, 2007
Posts: 4
Hi,

I have 2 tables

Table A:

number number,
name1 varchar20,
name2 varchar20,
name3 varchar20,
name4 varchar20,
name5 varchar20,
name6 varchar20,
name7 varchar20,
name8 varchar20,
name9 varchar20,
name10 varchar20,
name11 varchar20,
name12 varchar20,
name13 varchar20,
name14 varchar20,
name15 varchar20.

etc..

Table B:

name varchar20,

x number,

y number,

etc...

name field on Table B is refered by all the 15 columns of Table A.

Pojos:

A.java:

private B b1;
private B b2;
private B b3;
private B b4;
private B b5;
private B b6;
private B b7;
private B b8;
private B b9;
private B b10;
private B b11;
private B b12;
private B b13;
private B b14;
private B b15;
private Integer number;

etc..

B.java:

private string name;

private Integer x;

private Integer y;

etc..

Hbms:

A.hbm.xml:

15 number of many-to-one mappings for B.java.

etc....

B.hbm.xml:

Properties for all the columns of B table.

15 number of collections for table A, for each of the 15 columns.


My requirement:

Instead of writing 15 properties in A.java.

Can I have an Array of object type B, in A.java.

It will be more convenient, and flexible.

Thanks in advance,
Ramana Reddy
[ April 16, 2007: Message edited by: jai shreeram ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Not sure I understand your data model. Can you post the DDL?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16622

Yes, exactly the title of your topic. In order to achieve what you want, you will have to create your own Custom UserType that will read the data from the database and you will code the construction of that Collection of type Bs. There is no regular mapping that you can do to achieve that with the data model that you have.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: Dealing with Custom User Types as an Array in Hibernate
 
Threads others viewed
Interesting interview programming problem
Copy value from attribute a1 in class A.java to attribute b1 in class B.java using 0bject mapping
Question for Mr. Michael Ernest
using package getting compiler error
JPA: composite key and deleting records problem
developer file tools