-->
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.  [ 15 posts ] 
Author Message
 Post subject: @Index not working?
PostPosted: Tue Jul 24, 2007 9:20 am 
Newbie

Joined: Tue Jul 24, 2007 9:14 am
Posts: 8
Hello,

I'm rather new to Hibernate so I guess I'm just doing something stupid, so any help greatly appreciated...
I'm using JBoss 4.0.5 with EJB3 profile. I'm trying to create database indexes using Hibernate @Index annotation, so I have an Entity like:
Code:
@Entity
@Table(name="keyword")
@org.hibernate.annotations.Table(appliesTo="keyword", indexes={
      @Index(name="keywordIndex", columnNames={ "keyword" })
})
public class Keyword implements Serializable
{
  // ...

    @Column(name="keyword")
    public String getKeyword()
    {
       return keyword;
    }
}

... but no indexes are being created. What am I doing wrong?
Thanks!
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 25, 2007 3:06 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
and hibernate.hbm2ddl.auto is set to create?
Which version of HAnnotation are you using (you can see that in the log file)? can you try with the latest version

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 1:01 pm 
Newbie

Joined: Tue Jul 24, 2007 9:14 am
Posts: 8
Thanks a lot! Indeed I had hibernate.hbm2ddl.auto=update; setting it to create did the trick. But as a side effect it seems that now with every start of the server the database schema is re-created and I lost all the data. Is it possible to avoid that?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 26, 2007 1:36 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
if you want to be able to update the schema each time you deploy wo losing data, no.
But update should not be done in production.
People usually use the schemaexport ant task to generate a DDL file that they apply manually in prod.
In dev mode data usually is create with unit tests each time

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 1:33 pm 
Newbie

Joined: Tue Jul 24, 2007 9:14 am
Posts: 8
Well, the problem is that the data for my application (for development mode) is rather vast so I don't want to recreate it too often. But now every time I change the DB schema I deploy with hibernate.hbm2ddl.auto=create and re-create the data and otherwise just deploy with hibernate.hbm2ddl.auto=update and it works just fine for me. So thanks a lot for your help.

One more question if I may: is it possible to create indexes for join tables? (for instance coming with M-N relations). I did not manage to do that... any hints?

Cheers,
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Thu Aug 02, 2007 3:04 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
not today, but I never understood the need provided that the PK are expressed already

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 2:23 pm 
Newbie

Joined: Tue Jul 24, 2007 9:14 am
Posts: 8
Right you are. The problem is I don't know how to specify the primary key for a join table via EJB3 annotations. Do you happen to know how to do that?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 2:39 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
you don't need to, Hibernate knows which columns are part of the PK if a PK makes sense.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 03, 2007 2:47 pm 
Newbie

Joined: Tue Jul 24, 2007 9:14 am
Posts: 8
I'm not sure if I understand what do you mean. I happen to have a many-to-many relationship and I end up with having a join table with no primary key (I'm using postgresql). How can I enforce that the PK is specified?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 1:57 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Maybe you're using a bag where pk are undefined.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 2:01 pm 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
Hi,

I also use PostgreSQL, and a @ManyToMany creates a join table with 2 foreign keys (as expected), and also a composite primary key on both of the fk's.

Cheers,

Andy

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 2:09 pm 
Newbie

Joined: Tue Jul 24, 2007 9:14 am
Posts: 8
Hmm... My field looks as follows:
Code:
@ManyToMany(cascade={CascadeType.MERGE, CascadeType.REFRESH, CascadeType.PERSIST})
@JoinTable(name="task_catPositionsClosure")
public Collection<CatalogueEntry> getCatPositionsClosure()

and as a result I obtain a postgresql table with two foreign keys but with no primary key. Any ideas what am I doing wrong?
Thanks in advance!
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 2:14 pm 
Senior
Senior

Joined: Tue Jul 25, 2006 9:05 am
Posts: 163
Location: Stuttgart/Karlsruhe, Germany
how is the other side of the relationship defined ?

_________________
Rules are only there to be broken


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 07, 2007 2:34 pm 
Newbie

Joined: Tue Jul 24, 2007 9:14 am
Posts: 8
Ahh, sorry, here it goes:
Code:
@ManyToMany(mappedBy="catPositionsClosure")
public Set<Task> getCatEntryTasks()
{
return catEntryTasks;
}

At first I thought that indeed this is due to the use of Set but I changed it to Collection and still no primary key is being created...
Adam


Top
 Profile  
 
 Post subject:
PostPosted: Sat Aug 11, 2007 3:52 pm 
Newbie

Joined: Tue Jul 24, 2007 9:14 am
Posts: 8
Dear Andy,

Quote:
I also use PostgreSQL, and a @ManyToMany creates a join table with 2 foreign keys (as expected), and also a composite primary key on both of the fk's.


Can you show me how do you define relations so that you get a composite primary key?
Thank a lot,
Adam


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 15 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.