-->
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: Order of fields in table and primary key
PostPosted: Mon Feb 06, 2006 4:17 am 
Newbie

Joined: Thu Dec 22, 2005 4:09 am
Posts: 8
I use annotations and inheritance for beans and id's. This works good, but I have problem with generated SQL for creating database schema. Hibernate declares fields in primary key in "reverse" order, i.e. "nearest" fields first and then fields from superclass. This is bad, because for composite id's we need "master" fields first, because this index is better, we can for example use this index to select Shift instances by laboratory.

Is it possible change order of fields in primary key? Can you change this default behaviour to more practical?

PS. Order of fields in table itself also "reversed", and also would be good to have them in better order - from superclass to sub-class.


Hibernate version: Hibernate 3.1.1, Hibernate Annotations 3.1 beta 8

Mapping documents:

@AccessType("field")
@MappedSuperclass
public class AbstractLaboratoryId extends AbstractCompositeId {
private static final long serialVersionUID = -4959976895077908661L;
long laboratory_id;
////////////////////////////////////////////////////////////////////////////
//
// Конструктор
//
////////////////////////////////////////////////////////////////////////////
public AbstractLaboratoryId(Laboratory laboratory) {
laboratory_id = laboratory.getId();
}
}


@AccessType("field")
@MappedSuperclass
public class ShiftId extends AbstractLaboratoryId {
private static final long serialVersionUID = 605527818398859417L;
long shift_id;
////////////////////////////////////////////////////////////////////////////
//
// Constructor
//
////////////////////////////////////////////////////////////////////////////
public ShiftId(Laboratory laboratory, long shift_id) {
super(laboratory);
this.shift_id = shift_id;
}
}


@Entity
@SequenceGenerator(name = "SEQ", sequenceName = "SEQ_SHIFT")
public class Shift extends AbstractLaboratoryBean {
////////////////////////////////////////////////////////////////////////////
//
// Constructor
//
////////////////////////////////////////////////////////////////////////////
public Shift(Laboratory laboratory, long shift_id) {
super(laboratory);
m_id = new ShiftId(laboratory, shift_id);
}
////////////////////////////////////////////////////////////////////////////
//
// Object
//
////////////////////////////////////////////////////////////////////////////
@Override
public String toString() {
return BeanUtils2.toString(this, "id");
}
////////////////////////////////////////////////////////////////////////////
//
// Id
//
////////////////////////////////////////////////////////////////////////////
private ShiftId m_id;
@EmbeddedId
public ShiftId getId() {
return m_id;
}
public void setId(ShiftId id) {
m_id = id;
}
}


Name and version of the database you are using: Oracle 9i

The generated SQL (show_sql=true):

create table Shift (shift_id number(19,0) not null, laboratory_id number(19,0) not null, version number(19,0) not null, primary key (shift_id, laboratory_id));

Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 08, 2006 2:17 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
create an explicit index.
Your choice isn't a more practical choice, it's very applciation dependant. superclass ids might not be selective enough

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 1:00 am 
Newbie

Joined: Thu Dec 22, 2005 4:09 am
Posts: 8
emmanuel wrote:
create an explicit index.
Your choice isn't a more practical choice, it's very applciation dependant. superclass ids might not be selective enough


May be selective, may be no. But if index is here, consumes space in database we should use it as much as possible. Can I configure order of fields in primary key index? I don't want create additional index - this is just space lost.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 09, 2006 9:53 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
no, ordering is undefined.

_________________
Emmanuel


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.