-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Hibernate not creating indexes with JPA
PostPosted: Wed Oct 14, 2009 12:48 pm 
Newbie

Joined: Wed Oct 14, 2009 12:28 pm
Posts: 4
Hello,

I have a simple setup with hibernate entity manager and a Derby database instance.

I have this simple entity class:

Code:
@Entity
public class Entity
{
   private long id;
   private String name;

   @Id
   public long getId()
   {
      return id;
   }

   public void setId(long id)
   {
      this.id = id;
   }

   @Index(name="idx")
   public String getName()
   {
      return name;
   }

   public void setName(String name)
   {
      this.name = name;
   }
      
}


When the table is auto created by hibernate, there is no index for the name column:

Code:
ij> describe entity;
COLUMN_NAME         |TYPE_NAME|DEC&|NUM&|COLUM&|COLUMN_DEF|CHAR_OCTE&|IS_NULL&
------------------------------------------------------------------------------
ID                  |BIGINT   |0   |10  |19    |NULL      |NULL      |NO
NAME                |VARCHAR  |NULL|NULL|255   |NULL      |510       |YES

2 rows selected
ij> show indexes from entity;
TABLE_NAME          |COLUMN_NAME         |NON_U&|TYPE|ASC&|CARDINA&|PAGES
----------------------------------------------------------------------------
ENTITY              |ID                  |false |3   |A   |NULL    |NULL


Any help please? I guess I am missing something pretty simple.

Thanks
Neil


Top
 Profile  
 
 Post subject: Re: Hibernate not creating indexes with JPA
PostPosted: Thu Oct 15, 2009 6:15 am 
Newbie

Joined: Wed Oct 14, 2009 12:28 pm
Posts: 4
Hello,

I have now also tried this with Oracle 10g, Hsql and Derby. It seems the indexes are never created and with derby, unique contraints are also not applied (this may be a derby feature as I havn't looked this up yet).

The reference doc for annotations has this example:

Quote:
2.4.3.4. Index

You can define an index on a particular column using the @Index annotation on a one column property, the columnNames attribute will then be ignored

@Column(secondaryTable="Cat1")
@Index(name="story1index")
public String getStoryPart1() {
return storyPart1;
}


But 'Column' does not seem to have a 'secondaryTable' attribute?

Neil


Top
 Profile  
 
 Post subject: Re: Hibernate not creating indexes with JPA
PostPosted: Thu Oct 15, 2009 6:18 am 
Newbie

Joined: Wed Oct 14, 2009 12:28 pm
Posts: 4
Hello,

I have now also tried this with Oracle 10g, Hsql and Derby. It seems the indexes are never created and with derby, unique contraints are also not applied (this may be a derby feature as I havn't looked this up yet).

The reference doc for annotations has this example:

Quote:
2.4.3.4. Index

You can define an index on a particular column using the @Index annotation on a one column property, the columnNames attribute will then be ignored

@Column(secondaryTable="Cat1")
@Index(name="story1index")
public String getStoryPart1() {
return storyPart1;
}


But 'Column' does not seem to have a 'secondaryTable' attribute?

Neil


Top
 Profile  
 
 Post subject: Re: Hibernate not creating indexes with JPA
PostPosted: Thu Oct 15, 2009 7:01 am 
Newbie

Joined: Wed Oct 14, 2009 12:28 pm
Posts: 4
OK, finally got to the bottom of this and it was due to spring...not such a big surprise I guess.

seems that use of: org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean is not good for hibernate, and instead I used: org.springframework.orm.jpa.LocalEntityManagerFactoryBean


Neil


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.