-->
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.  [ 1 post ] 
Author Message
 Post subject: Let 2 different mapping files work with same domain
PostPosted: Thu Mar 31, 2011 10:29 am 
Newbie

Joined: Fri Feb 18, 2011 5:23 am
Posts: 2
Hi,

At my company we need to make sure our application supports 3 databases: Sybase, SQL and Oracle.

In our mapping files we use for our ID's the generated property which refers to a generator of our own. For Oracle we make sure sequences are being used.

For 1 table, we're experiencing problems as it's a difficult case.

This Address table has a PK consisting of 2 fields. So a composite ID in the mapping file.

The PK consists of TnrAddress and TnrID. This last one will always have the same value "-1". This is now the case, it used to be different. That's why we can't change this way of working. So it's actually only TnrAddress that will be unique and that would suffice to be our PK, but because it used to be different, we can't change this.

Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2"
        namespace="Domain.Address" assembly="Domain">

  <class name="Address" table="ADDRESS">
    <composite-id name="ID" class="IDComposite_Address">
      <key-property name="TnrAddress" column="TNR_ADDRESS" type="Int32"/>
      <key-many-to-one name="Identity" class="Identity" column="TNR_ID"/>
    </composite-id>
   
    <!-- All my properties are here -->
  </class>
</hibernate-mapping>


In a composite ID you cannot add a generated value in it. So I had to make sure that TnrAddress was set manually. This is no problem for Sybase and SQL.

For Oracle this is a problem as Oracle requires sequences to be used all the time to calculate the next tnr.
I've succeeded in making sure a sequence was used for the oracle dialect, but that sequence was executed on the entire composite ID while it only has to be executed on 1 column, i.e. TnrAddress. And as far as I know, it's not possible to put a sequence on only 1 column of a composite ID.

So perhaps there may be another solution. Create a mapping file specifically for Oracle. That would look like this:

Code:
<?xml version="1.0" encoding="utf-8"?>
<hibernate-mapping default-cascade="none" xmlns="urn:nhibernate-mapping-2.2"
        namespace="Domain.Address" assembly="Domain">

  <class name="Address" table="ADDRESS">
    <id name="TnrAddress" column="TNR_ADDRESS" type="Int32">
      <generator class="sequence" />
    </id>
   
    <!-- All my properties are here -->

    <many-to-one name="Identity" class="Identity" column="TNR_ID" not-null="true"/>
  </class>
</hibernate-mapping>


I can then choose at startup which mapping file should be used depending on the dialect (more info here).

But I'll still have problems with my domain class. As this domain class was created to work with the first mapping file. This is my domain class:

Code:
public class IDComposite_Address
    {
        public virtual int TnrAddress { get; set; }
        public virtual Identity Identity { get; set; }

        public override bool Equals(object obj) { ... }

        public override int GetHashCode() { ... }
    }

    public class Top_Address
    {
        public virtual IDComposite_TopAddress ID { get; set; }
        public virtual string nmStreetAdd{ get; set; }
        public virtual string nmStreetAdd2{ get; set; }
        public virtual string nmStreetAdd3{ get; set; }
        public virtual string nmAddress{ get; set; }
        public virtual decimal? dPosx{ get; set; }
        public virtual decimal? dPosy{ get; set; }
        public virtual string HouseNumber { get; set; }
        public virtual string BusNumber { get; set; }
        public virtual string PostalCode { get; set; }
        public virtual string City { get; set; }
        public virtual string Country { get; set; }
        public virtual string Email { get; set; }
        public virtual string Phone { get; set; }
        public virtual string CellPhone { get; set; }
        public virtual string NmAddress2 { get; set; }
        public virtual Int32 Active { get; set; }
        public virtual string Language { get; set; }
        public virtual DateTime? AmFrom { get; set; }
        public virtual DateTime? AmUntil { get; set; }
        public virtual DateTime? PmFrom { get; set; }
        public virtual DateTime? PmUntil { get; set; }
        public virtual string Remark { get; set; }
        public virtual string ExtraInformation { get; set; }
        public virtual char AddressType { get; set; }
        public virtual string AddressOrPlace { get; set; }
    }


Is there any way to make sure that both mapping files can work with the same domain class? Or is there any other way I can solve my problem?

Already thanks for your help!!

Jeremy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.