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.  [ 3 posts ] 
Author Message
 Post subject: giving non-primary key as foreign key???
PostPosted: Fri Apr 10, 2009 1:21 pm 
Newbie

Joined: Tue Apr 07, 2009 8:48 am
Posts: 14
Location: Kerala,India
Can we give a non-primary key of one table as a foreignkey of another table in oracle?
I tried it by setting the non-primary key as UNIQUE..It worked then.

But a problem arises when i try to genarate the code by reverse engineering in NetBeans 6.5 . It is not recognising the relation as a Foreign key relation.

ie :
CREATE TABLE A(
Aa NUMBER(2) PRIMARY KEY,
Ab VARCHAR2(5) UNIQUE
);

CREATE TABLE B(
Ba NUMBER(2) PRIMARY KEY,
Bb CONSTRAINT B_Bb_fkey REFERENCES A(Ab)
);

The table is getting created..!!!
But the the foreignkey relation is not recognised by Net Beans.

Is it because i have mapped a foreign key against a non-primary key???


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 10, 2009 4:24 pm 
Newbie

Joined: Tue Oct 02, 2007 10:54 pm
Posts: 4
If your question is about your mapping post us your mapping file.

I think it can be done using property-ref property.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 11, 2009 1:16 am 
Newbie

Joined: Tue Apr 07, 2009 8:48 am
Posts: 14
Location: Kerala,India
thanks for lookin into the post these are pojo and mapping files generated using Reverse engineering.



A.java
Code:
package sixpack;
// Generated Apr 11, 2009 10:18:38 AM by Hibernate Tools 3.2.1.GA



/**
* A generated by hbm2java
*/
public class A  implements java.io.Serializable {


     private byte aa;
     private String ab;

    public A() {
    }

   
    public A(byte aa) {
        this.aa = aa;
    }
    public A(byte aa, String ab) {
       this.aa = aa;
       this.ab = ab;
    }
   
    public byte getAa() {
        return this.aa;
    }
   
    public void setAa(byte aa) {
        this.aa = aa;
    }
    public String getAb() {
        return this.ab;
    }
   
    public void setAb(String ab) {
        this.ab = ab;
    }
}



A.hbm.xml
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 11, 2009 10:18:40 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="sixpack.A" table="A" schema="user">
        <id name="aa" type="byte">
            <column name="AA" precision="2" scale="0" />
            <generator class="assigned" />
        </id>
        <property name="ab" type="string">
            <column name="AB" length="10" unique="true" />
        </property>
    </class>
</hibernate-mapping>


B.java
Code:
package sixpack;
// Generated Apr 11, 2009 10:18:38 AM by Hibernate Tools 3.2.1.GA



/**
* B generated by hbm2java
*/
public class B  implements java.io.Serializable {


     private byte ba;
     private String bb;

    public B() {
    }

   
    public B(byte ba) {
        this.ba = ba;
    }
    public B(byte ba, String bb) {
       this.ba = ba;
       this.bb = bb;
    }
   
    public byte getBa() {
        return this.ba;
    }
   
    public void setBa(byte ba) {
        this.ba = ba;
    }
    public String getBb() {
        return this.bb;
    }
   
    public void setBb(String bb) {
        this.bb = bb;
    }
}


B.hbm.xml


Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<!-- Generated Apr 11, 2009 10:18:40 AM by Hibernate Tools 3.2.1.GA -->
<hibernate-mapping>
    <class name="sixpack.B" table="B" schema="user">
        <id name="ba" type="byte">
            <column name="BA" precision="2" scale="0" />
            <generator class="assigned" />
        </id>
        <property name="bb" type="string">
            <column name="BB" length="10" />
        </property>
    </class>
</hibernate-mapping>



hibernate.fg.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
  <session-factory>
    <property name="hibernate.dialect">org.hibernate.dialect.DerbyDialect</property>
    <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property>
    <property name="hibernate.connection.url">"url"</property>
    <property name="hibernate.connection.username">user</property>
    <property name="hibernate.connection.password">pass</property>
    <mapping resource="sixpack/B.hbm.xml"/>
    <mapping resource="sixpack/A.hbm.xml"/>
  </session-factory>
</hibernate-configuration>


hibernate.reveng.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-reverse-engineering PUBLIC "-//Hibernate/Hibernate Reverse Engineering DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-reverse-engineering-3.0.dtd">
<hibernate-reverse-engineering>
  <schema-selection match-schema="user"/>
  <table-filter match-name="A"/>
  <table-filter match-name="B"/>
</hibernate-reverse-engineering>


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