• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to solve Repeated column in mapping for entity:

 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All

Could Anyone could throw some hints for me to solve
Repeated column in mapping for entity problem ?

My Database design is like below( could not change , it is from others)
Table Clubs have Table Employees and Employeers through foreign primary key
refereneced and depat_id are repeated ,

For mapping file of Club, i must set , insert and update to false.
at lease for either Employeer or Employee. otherwise it will have repeated
colum exception for Hibernate.
but if i set eiter one for update and insert to false.
i could not insert or update this record.
How to solve this problem?
Actually i just need Club to overwrite depat_id colum.

How to do it with Hibernate?

Thanks in advance for your input
<many-to-one
name="employeer"
class="org.hibernate.test.Employeer"
not-null="true"
insert="false"
update="false"
>

CREATE TABLE EMPLOYEES (
depat_id int NOT NULL ,
employee_id int NOT NULL,
salary decimal(20,4) NOT NULL,
primary key (depat_id,employee_id)
)

CREATE TABLE EMPLOYEERS (
depat_id int NOT NULL ,
employeer_id int NOT NULL,
salary decimal(20,4) NOT NULL,
primary key (depat_id,employeer_id)
)

CREATE TABLE CLUBS(
club_id int NOT NULL PRIMARY KEY,
depat_id int NOT NULL ,
employee_id int NOT NULL,
employeer_id int NOT NULL,
foreign key (employee_id, depat_id) references employees (depat_id,employee_id),
foreign key (employeer_id, depat_id) references employeers (depat_id,employeer_id)
)

<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >

<hibernate-mapping>
<!--
Created by the Middlegen Hibernate plugin 2.1

http://boss.bekk.no/boss/middlegen/
http://www.hibernate.org/
-->

<class
name="org.hibernate.test.Club"
table="CLUBS"
>
<meta attribute="class-description" inherit="false">
@hibernate.class
table="CLUBS"
</meta>

<id
name="clubId"
type="java.lang.Integer"
column="CLUB_ID"
>
<meta attribute="field-description">
@hibernate.id
generator-class="assigned"
type="java.lang.Integer"
column="CLUB_ID"

</meta>
<generator class="assigned" />
</id>


<!-- Associations -->

<!-- bi-directional many-to-one association to Employee -->
<many-to-one
name="employee"
class="org.hibernate.test.Employee"
not-null="true"
insert="true"
update="true"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="EMPLOYEE_ID"
@hibernate.column name="DEPAT_ID"
</meta>
<column name="EMPLOYEE_ID" />
<column name="DEPAT_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to Employeer -->
<many-to-one
name="employeer"
class="org.hibernate.test.Employeer"
not-null="true"
insert="false"
update="false"
>
<meta attribute="field-description">
@hibernate.many-to-one
not-null="true"
@hibernate.column name="EMPLOYEER_ID"
@hibernate.column name="DEPAT_ID"
</meta>
<column name="EMPLOYEER_ID" />
<column name="DEPAT_ID" />
</many-to-one>

</class>
</hibernate-mapping>
 
Ranch Hand
Posts: 662
Eclipse IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
try to have a update="false" insert="false" in <many-to-one>.
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic