Win a 3 month subscription to Marco Behler Videos this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How do you Map String Array to JPA ?  RSS feed

 
tangara goh
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am now refactoring my code to adapt to JPA.

But, the same old problem in JDBC is now back to haunt me.

How do I map String Array to JPA, specifically using Eclipse-Link without Hibernate ?

So, I have this class - Subject that contains sub_id and subjects which is in Array.

Do I use HashMap to do it or ?

 
Dave Tolls
Ranch Hand
Posts: 2729
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Again, why does your Subject class have an array of subjects?
 
tangara goh
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:Again, why does your Subject class have an array of subjects?


Hi Dave,

After analysing very hard and studying various other many to many relationships table, I realise I still can't run away from array.

Please see the schema for a full understanding.

database-schema-latest.jpg
[Thumbnail for database-schema-latest.jpg]
 
Dave Tolls
Ranch Hand
Posts: 2729
30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But those tables don't show that the Java side Subject should have an array in it.

A Subject has an id, a name, and (for some reason) a code.
It might (depending on how you want to model the relationships) have a List<Tutor>, but it definitely doesn't have a List<Subject name>.
Your Tutor will likely have a List<Subject>.

As an aside, there is no need for your mapping table to duplicate the columns from the Subject table.
 
tangara goh
Ranch Hand
Posts: 240
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave Tolls wrote:But those tables don't show that the Java side Subject should have an array in it.

A Subject has an id, a name, and (for some reason) a code.
It might (depending on how you want to model the relationships) have a List<Tutor>, but it definitely doesn't have a List<Subject name>.
Your Tutor will likely have a List<Subject>.

As an aside, there is no need for your mapping table to duplicate the columns from the Subject table.


I am not using a List of SubjectName but an array because I need to use ParameterValues.  Hope you get the point.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!