Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Wrong order in arguments constructor during generation
PostPosted: Tue Jul 27, 2010 8:37 am 
Newbie

Joined: Tue Jul 27, 2010 8:22 am
Posts: 4
Hello

I'm using Hibernate 3.3.2.GA and an Oracle database

I have two different machines with the same settings when I generate code I get different results.
for an entity, the Hibernate generator changes the order of the arguments of the constructor

Example:
hibernate.cfg.xml
Code:
<session-factory>
        <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>

        <property name="hibernate.connection.url">jdbc:oracle:thin:@[IP]:[PORT]:DEV26</property>
        <property name="hibernate.connection.username">user</property>
        <property name="hibernate.connection.password">pass</property>

        <property name="hibernatetool.metadatadialect">org.hibernate.cfg.reveng.dialect.OracleMetaDataDialect</property>
        <property name="current_session_context_class">thread</property>
    </session-factory>


sql for table creation - DDL
Code:
  CREATE TABLE "TRAINNING"."ITEM"
   (   "ID_ITEM" NUMBER(24,0) NOT NULL ENABLE,
   "CODE" VARCHAR2(200 CHAR),
   "NAME" VARCHAR2(200 CHAR),
   "BLOCKED" VARCHAR2(1 CHAR),
   "ID_ITEM_CATEGORY" NUMBER(24,0) NOT NULL ENABLE,
   "ID_ITEM_UM" NUMBER(24,0) NOT NULL ENABLE,
   "ID_ITEM_STATUS" NUMBER(24,0) NOT NULL ENABLE,
   CONSTRAINT "ITM_PK" PRIMARY KEY ("ID_ITEM"),
   CONSTRAINT "ITM_BK" UNIQUE ("CODE"),
   CONSTRAINT "ITM_IC_FK" FOREIGN KEY ("ID_ITEM_CATEGORY")
     REFERENCES "TRAINNING"."_ITEM_CATEGORY" ("ID_ITEM_CATEGORY") ENABLE,
   CONSTRAINT "ITM_IUM_FK" FOREIGN KEY ("ID_ITEM_UM")
     REFERENCES "TRAINNING"."_ITEM_UNIT_MEASURE" ("ID_ITEM_UNIT_MEASURE") ENABLE,
   CONSTRAINT "ITM_ISTAT_FK" FOREIGN KEY ("ID_ITEM_STATUS")
     REFERENCES "TRAINNING"."ITEM_STATUS" ("ID_ITEM_STATUS") ENABLE
   ) PCTFREE 10 PCTUSED 40 INITRANS 1 MAXTRANS 255 NOCOMPRESS LOGGING
  STORAGE(INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS 2147483645
  PCTINCREASE 0 FREELISTS 1 FREELIST GROUPS 1 BUFFER_POOL DEFAULT)
  TABLESPACE "TABLE_M" ;



As result I have for the entity constructor:
Expected (one of the machines have this)
Code:
@Entity
@Table(name="ITEM",schema="TRAINNING")
public class Item extends itemGeneric
{
   private static final long serialVersionUID = 1L;
   public Item(String code, PfwItemUnitMeasure pfwItemUnitMeasure, PfwItemCategory pfwItemCategory, PfwItemStatus pfwItemStatus)
   {   
      super(code, pfwItemUnitMeasure, pfwItemCategory, pfwItemStatus);
   }


Obtained (in other machine):
Code:
@Entity
@Table(name="ITEM",schema="TRAINNING")
public class Item extends itemGeneric
{
   public Item(String code, PfwItemStatus pfwItemStatus, PfwItemCategory pfwItemCategory, PfwItemUnitMeasure pfwItemUnitMeasure)
   {   
      super(code, pfwItemStatus, pfwItemCategory, pfwItemUnitMeasure);
   }


My explanation is that the order is defined by the order of creation... but Why? How to change?

pfwItemStatus, pfwItemCategory and pfwItemUnitMeasure are FKs on the table. pfwItemStatus and pfwItemUnitMeasure appears swapped


Does anyone know why this happens or how to force the order?

Thanks

Miguel


Last edited by ask4me on Thu Nov 18, 2010 7:18 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: Arguments in wrong order
PostPosted: Thu Nov 18, 2010 7:16 am 
Newbie

Joined: Tue Jul 27, 2010 8:22 am
Posts: 4
According to tests that I have done , the problem
- is not the JDBC driver
- is not the database/tables (unless changes are made - ALTER TABLE)

appears to be the eclipse plugin, but don't know how to solve ...

the solution may be to force an alphabetical order, but this is not the idea

I change the files
{PROJECT_NAME}\.metadata\.plugins\org.eclipse.core.runtime\.settings
-> org.eclipse.jdt.launching.prefs
(or/and)
-> org.eclipse.jst.jsp.core.prefs [ org.eclipse.jst.jsp.core.taglib.TaglibIndex=DIRTY and not CLEAN ]

but this is stupid!!!


Top
 Profile  
 
 Post subject: Re: Wrong order in arguments constructor during generation
PostPosted: Fri Apr 20, 2012 4:14 am 
Newbie

Joined: Wed Apr 18, 2012 4:37 am
Posts: 7
I also found out, that the problem is due to the eclipse DTP plugin used to connect to the database.
I am using an Oracle 11g database. The original create scripts have a different order of the columns than the ones I create using DTP when selecting "Generate DDL...".

I am currently trying to find a way to define the order of the columns, e.g. in some hibernate configuration file.
As I am generating the Hibernate Mapping Files, this is no option for me. So the only place left to define those is.. the reveng.xml file.
If I find a solution, I will post it here.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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.