-->
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.  [ 9 posts ] 
Author Message
 Post subject: Help not add unnecessary columns in data base
PostPosted: Mon Apr 16, 2007 1:49 am 
Newbie

Joined: Fri Apr 13, 2007 8:38 am
Posts: 12
problem:
iam using postgresql database.

i have two tables one is class_definition with having column named class_id_pk which is primary key, and there is another table state_classes with column class_id_fk having the foreign key reference of class_id_pk. when i load session factory, it creates the extra empty column with name class_id_pk in state_classes table.in postgresql database.. i dont want this to happen adding unnecessary extra column...

is there any attribute to avoid creation of extra column?

ex: table1 : class_definition
columns: class_id_pk, class_name;
class_id_pk primary key btree (class_id_pk)


table2: state_classes
columns: state_classes_id_pk, class_id_fk

class_id_fk FOREIGN KEY (class_id_fk) REFERENCES class_definition(class_id_pk) MATCH FULL ON UPDATE NO ACTION ON DELETE CASCADE,

after running session factory, with in hibernate.cfg.xml having attribute hbmddl_auto update propery,,


it creates extra columns in state_classes, after generating hibernate generating mappings we get in postgres data base with

table2: state_classes
columns: state_classes_id_pk, class_id_fk. class_id_pk
,


Last edited by skandsoft on Tue Apr 17, 2007 12:47 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 16, 2007 3:00 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
What is your hibernate.cfg.xml file? Hibernate doesn't do any update to the schema unless you put hbm2ddl option in your config.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: i added <property name="hibernate.hbm2ddl.auto"
PostPosted: Tue Apr 17, 2007 12:49 am 
Newbie

Joined: Fri Apr 13, 2007 8:38 am
Posts: 12
i added <property name="hibernate.hbm2ddl.auto"

but, is not another way, to avoid an extra column not to add to database, with out disturbing auto update as false. (only particular column should not be updated, is any attribute to declare in hbm.xml file)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 2:05 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I I get you correctly, no. You can't ask to update the schema, but not the columns...

In your case, if Hibernate adds a column when accessing the schema, I think that's because your mapping is not correct.

See the different values of hbm2ddl.auto (the reference documentation): http://www.hibernate.org/hib_docs/v3/re ... properties

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: thankq for giving reply,,
PostPosted: Tue Apr 17, 2007 2:15 am 
Newbie

Joined: Fri Apr 13, 2007 8:38 am
Posts: 12
yes, u r correct, that is is the mistake done in mapping file, but as per the naming conventions given in data base side, (which is already created),
ex:- in class_definition table i have column like class_id_pk(primary key), which is reference to foreigh key of another table in state_classes like class_id_fk, which the both columns are same, but in hibernate when it is mapping it is treating both the columns has different, i need to tell that column on both tables are same, is their is not another solution rather then keeping hbm2ddl update=false.....


thanq,


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 10:36 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Sorry, I'm not sure I understand your problem. Could you explain it again ?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 12:56 am 
Newbie

Joined: Fri Apr 13, 2007 8:38 am
Posts: 12
having two talbes in db like: ---

class_definition

class_id_pk | integer |
class_name | character varying(200) |
class_description | character varying(200) |
Indexes: class_id_pk primary key btree (class_id_pk),

state_classes

state_classes_id_pk | integer | not null
state_id_fk | integer | not null
class_id_fk | integer | not null
Indexes: state_classes_pkey primary key btree (state_classes_id_pk)
Foreign Key constraints: fk_state_id FOREIGN KEY (state_id_fk) REFERENCES state_definition(state_id) ON UPDATE NO ACTION ON DELETE NO ACTION,
class_id_fk FOREIGN KEY (class_id_fk) REFERENCES class_definition(class_id_pk) ON UPDATE NO ACTION ON DELETE NO ACTION

In the above table class_id_fk is a foreign key for class_definition(class_id_pk), these two coumns are same, if we take class_id as column in tables, hibernate will not create any extra column in db, otherwise it creates an a extra column in state_classes with class_id_pk . which is unnecessary,,
to avoid this extra column, is their any attribute, is their


thanq.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 18, 2007 1:58 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I guess I begin understanding your case. If I'm right, there's no problem to do it with Hibernate.

Though I'm not completely sure:
you say you have two columns that are the same??? So, you don't have two columns, you have only one that is mapped more than once, that should be. Could you precise what you mean by "they are the same"?

Please maybe also show the DDL you should have and the mapping you have at the moment.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject: hi...
PostPosted: Wed Apr 18, 2007 2:11 am 
Newbie

Joined: Fri Apr 13, 2007 8:38 am
Posts: 12
CREATE TABLE class_definition (
class_id_pk integer DEFAULT nextval('class_id_pk_seq'::text) NOT NULL,
class_name character varying(200),
class_description character varying(200)
);


INSERT INTO class_definition VALUES (1,'NonWriteAclass', 'NonWriteAclass 1');
INSERT INTO class_definition VALUES (2,'NonWriteBclass', 'NonWriteBclass 1');
INSERT INTO class_definition VALUES (3,'vegetables', 'name of vegetables');
INSERT INTO class_definition VALUES (4,'test2', 'testdesc2');
INSERT INTO class_definition VALUES (5,'Pallet', 'Pallet');


CREATE TABLE state_classes (
state_classes_id_pk
state_id_fk integer,
class_id_fk integer
);

INSERT INTO state_classes VALUES (1,3007, 1);
INSERT INTO state_classes VALUES (2,3007, 2);
INSERT INTO state_classes VALUES (3,3009, 2);
INSERT INTO state_classes VALUES (4,3009, 1);
INSERT INTO state_classes VALUES (5,3013, 1);


class_definition.hbm.xml

<hibernate-mapping>
<class name="com.skandsoft.setu.pojos.classdefinition.ClassDefinition" table="class_definition" >

<id name="classIdPk" type="int" unsaved-value="null">
<column name="class_id_pk" not-null="true"/>
<generator class="org.hibernate.id.Assigned"></generator>
</id>

<property name="className" column="class_name" type="string" unique="true" access="field" />
<property name="classDescription" column="class_description" type="string" />

<set name="stateClasses" inverse="true" cascade="all">
<key>
<column name="class_id_pk" />
</key>
<one-to-many class="com.skandsoft.setu.pojos.stateclasses.StateClasses"/>
</set>

state_classes.hbm.xml
<hibernate-mapping>

<class name="com.skandsoft.setu.pojos.stateclasses.StateClasses" table="state_classes">

<id name="stateClassesIdPk" type="java.lang.Integer" unsaved-value="null" >
<column name="state_classes_id_pk" not-null="true"/>
<generator class="org.hibernate.id.Assigned"></generator>
</id>

<many-to-one name="classDefinition" class="com.skandsoft.setu.pojos.classdefinition.ClassDefinition" not-null="true" column="class_id_fk" foreign-key="class_id_fk" cascade="all" />


</class>
</hibernate-mapping>





when we run session factory, it creates class_id_pk column in state_classes table db... which i dont want to map. becoz it is already have column with class_id_fk which is same..but i should be keep in hibernate.cfg.xml with attribute like <property name="hibernate.hbm2ddl.auto">
update
</property becoz i should update some columns...

tankq..
_


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