Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What does @ElementCollection with @Column mean ?

 
Sreyan Chakravarty
Ranch Hand
Posts: 65
Firefox Browser MyEclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have come across this piece of code -:



From the Oracle documentation over here http://docs.oracle.com/javaee/6/api/javax/persistence/CollectionTable.html

Why specify @Column after @ElementCollection what does that mean ?

I have used the following pattern in my code and I have noticed no difference whatsoever. So why use it ?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I have a doubt about JPA, I always check the Java Persistence Wikibook first. Most of the time my doubts are cleared, it's really an awesome resource! Here is the page about ElementCollection (and @CollectionTable) which also has an example of @ElementCollection followed by @Column.
 
Sreyan Chakravarty
Ranch Hand
Posts: 65
Firefox Browser MyEclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Roel De Nijs wrote:When I have a doubt about JPA, I always check the Java Persistence Wikibook first. Most of the time my doubts are cleared, it's really an awesome resource! Here is the page about ElementCollection (and @CollectionTable) which also has an example of @ElementCollection followed by @Column.


So correct me if I am wrong here. @Column is used to specify the name of that column which is created in the sub table ? In the above example the column will be named "name" and the value will be varchar(50) right ?
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sreyan Chakravarty wrote:@Column is used to specify the name of that column which is created in the sub table ? In the above example the column will be named "name" and the value will be varchar(50) right ?

That's indeed my understanding as well!

It's used when you have a basic collection (that's a collection of strings, integers,...). Then @Column will be the name of the column where the strings, integers,... will be stored. With a complex type (like Phone), the column names will be mapped in the Phone class (and you'll use the @Column in this class).

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic