1

I have a model that looks like this:

@MappedSuperclass
@AccessType("field")
public abstract class BaseEntity {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "generator")
    @Column(name = "ID")
    private Long id;
}

@Entity
@Table(name = "MODEL")
@AccessType("field")
public class Model extends BaseEntity {
    @Column(name="ABC")
    private String abc;
}

No matter what I try I cannot seem to be able to move the location of the ID column in the generated INSERT or UPDATE sql queries. ID always ends up as the last column:

insert into MODEL (ABC, ID) values (?, ?)

Is there any way to force it otherwise?

Abdullah Jibaly
  • 53,220
  • 42
  • 124
  • 197
  • 1
    Why do you care? The order doesn't matter. – JB Nizet Aug 22 '11 at 21:31
  • 1
    It does in Oracle if the column ABC is a CLOB then it MUST be last. – Abdullah Jibaly Aug 22 '11 at 21:33
  • Do you have some reference to back up this claim? Hibernate seems to work fine with clobs and oracle. See http://stackoverflow.com/questions/1644559/hibernate-on-oracle-mapping-string-property-to-clob-column for example. Isn't it in the table (and not in the insert statement) that the CLOB must be at last position? – JB Nizet Aug 22 '11 at 21:47
  • This describes my exact same issue: http://www.odi.ch/weblog/posting.php?posting=496 – Abdullah Jibaly Aug 22 '11 at 21:52
  • Have you tried using an AttributeOverride, either on the Model class, or on an overridden getter for the ID field? – JB Nizet Aug 22 '11 at 22:11
  • I had tried the former (changed column name to IDXX but not the position), the latter I just tried but doesn't seem to work at all (maybe because the base class is using `@AccessType("field")`?). – Abdullah Jibaly Aug 22 '11 at 22:23

1 Answers1

0

This is a known Hibernate limitation; see this thread for details.

Since Hibernate will order generated SQL fields alphabetically, why not change the name of the CLOB field to ensure is comes last, such as by pre-pending it with "zzz" so that it becomes zzzAbc?

atrain
  • 9,139
  • 1
  • 36
  • 40
  • The order in the `create table` is not the problem, the ID is located first there as you mentioned. However, Hibernate still builds the query such that ID comes last :( in the `insert`. – Abdullah Jibaly Aug 23 '11 at 17:35