java - How to define index by several columns in hibernate entity? -
In the morning.
I need to add indexing to the hibernate unit. As I know it is possible to use index annotations to specify the index for different columns, but I need the index for many areas of the unit.
I've got googled and jboss annotation @table, which do this (by specification). But (I do not know) this functionality is not working that the jboss version is less than necessary, or maybe I do not understand how to use this comment, but ... a complex index has not been created.
Why the index can not be made?
jboss version 4.2.3.GA
unit example:
package somepackage; Import org.hibernate.annotations.Index; Import javax.preistence.Column; Import javax.preistence.Entity; Import javax.preistence.GeneratedValue; Import javax.preistence.Id; @ Entity @ org.hibernate.annotations.Table (Apply = House. TABLE_NAME, Index = {@ Index (name = "IDX_XDN_DFN", column name = {house. XDN, House.DFN})} Public square house { Public last fixed string TABLE_NAME = "home"; Public final static string XDN = "xdn"; Public last stable string DFN = "DFN"; @ ID @ Generated Values Private Long ID; @column (name = XDN) Private long xdn; @column (name = dfn) private long DFN; @college private string address; Public long id () {return id; } Public Zero Set ID (long id) {this.Id = id; } Public long getXdn () {Return xdn; } Public Zero Set XDN (long xdn) {this.xdn = xdn; } Public long DDN () {Return DFN; } Public Zero Set DFN (Long DFN) {this.dfn = dfn; } Public string getAddress () {return address; } Public Zero Setdude (String Address) {this.address = address; }}
When jboss / hibernate tries to create a "home" table, it throws an exception:
Reason: org.hibernate.AnnotationException : @orgHibernate.Notation An unknown table reference: Home
Please try the following:
< Pre> @Entity @ org.hibernate.annotations.Table (apply = house.TABLE_NAME, index = {@ index (name = "IDX_XDN_DFN", columnNames = {House.XDN, House.DFN})}) @Table (name = "house") Public square house {...}
Note that you should also allow a multi-column index to be created (depending on the index) :
@ index (name = "index1") public string getFoo (); @ Index (name = "index 1") public string getBar ();
PS: What version of Hibernation are you using BTW? What database / quote?
Comments
Post a Comment