-->
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.  [ 2 posts ] 
Author Message
 Post subject: interace / implementation revisited
PostPosted: Wed Feb 25, 2004 11:51 pm 
Newbie

Joined: Sat Feb 21, 2004 3:02 pm
Posts: 14
OK - I admit in do not get it and I need a good sample
I have 2 interfaces IProduct and ISupplier
There are 2 implementation ProductImpl and SupplierImpl

public inteface IProduct {
public Supplier getSupplier();
public void setSupplier(Supplier s);
}
public inteface ISupplier {
public Set getProducts();
public void setProducts(Set s); // this seems to be needed :-(
}
and then ProductImpl implements IProduct
and then SupplierImpl implements ISuppier

<hibernate-mapping>
<class name="com.microsoft.northwind.impl.ProductImpl" table="Products" >
<id name="ProductID" type="int" unsaved-value="null" >
<column name="ProductID" sql-type="int identity" not-null="true" />
<generator class="hilo" />
</id>
<many-to-one name="Supplier" column="SupplierID" not-null="false" />
</class>
<class name="com.microsoft.northwind.impl.SupplierImpl" table="Suppliers" >
<id name="SupplierID" type="int" unsaved-value="null" >
<column name="SupplierID" sql-type="int identity" not-null="true" />
<generator class="hilo" />
</id>
<set name="Products" table="Products" inverse="true" cascade="all" >
<key column="SupplierID" />
<one-to-many class="com.microsoft.northwind.ISupplier" />
</set>
</class>
</hibernate-mapping>
gives Association references unmapped class: com.microsoft.northwind.Supplier
I tried overriding configuration to 'correct' the issue but the error is in the final Binding class :-(

So i tried to use the Interface with a custom persistor which overeides instantiate to return the implementation
<!--persister="com.babel17.persistor.FrameworkPersister" >
<hibernate-mapping>
<class name="com.microsoft.northwind.IProduct" table="Products" persister="com.babel17.persistor.FrameworkPersister" >
<id name="ProductID" type="int" unsaved-value="null" >
<column name="ProductID" sql-type="int identity" not-null="true" />
<generator class="hilo" />
</id>
<many-to-one name="Supplier" column="SupplierID" not-null="false" />
</class>
<class name="com.microsoft.northwind.ISupplier" table="Suppliers" persister="com.babel17.persistor.FrameworkPersister" >
<id name="SupplierID" type="int" unsaved-value="null" >
<column name="SupplierID" sql-type="int identity" not-null="true" />
<generator class="hilo" />
</id>
<set name="Products" table="Products" inverse="true" cascade="all" >
<key column="SupplierID" />
<one-to-many class="com.microsoft.northwind.ISupplier" />
</set>
</class>
</hibernate-mapping>
Now the correct class is build by FrameworkPersister
but in loadFromResultSet I get
No persister for: com.microsoft.northwind.impl.ProductImpl
at net.sf.hibernate.impl.SessionFactoryImpl.getPersister(SessionFactoryImpl.java:344)
at net.sf.hibernate.impl.SessionImpl.getClassPersister(SessionImpl.java:2656)
at net.sf.hibernate.impl.SessionImpl.getPersister(SessionImpl.java:2663)
at net.sf.hibernate.loader.Loader.loadFromResultSet(Loader.java:544)

I have posted to the forum before and have recieved replies which are prompt but one sentence like
use the implementation -
All I want is apointer to a piece of sample code which actually enables me to treat my properties as
interfaces or just explain any solution short of implimenting the properties as implementations not interfaces - Help

_________________
Steven M. Lewis PhD
4221 105th Ave NE
Kirkland, WA 98033
425-889-2694
206-384-1340 (cell)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 26, 2004 12:34 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
There's this really great feature on this board to actually format code ;)

In the mapping you need to specificy the class, not the impl. In the class, simply specify the interface for the association. This is normal java semantics, a class is always castable to any interfaces it implements.

So, do:
Code:
public inteface IProduct
{
    public ISupplier getSupplier();
    public void setSupplier(ISupplier s);
}

public inteface ISupplier
{
    public Set getProducts();
    // this seems to be needed :-(
    //   of course, how else would hibernate "introduce this
    //   value into your instance.  Make it private if you want...
    public void setProducts(Set s);
}

public class ProductImpl implements IProduct
{
    ...
}

public class SupplierImpl implements ISupplier
{
    ...
}


<class name="ProductImpl" table="Products" >
    <id name="ProductID" type="int" unsaved-value="null" >
        <column name="ProductID" sql-type="int identity" not-null="true" />
        <generator class="hilo" />
    </id>
    <many-to-one name="SupplierImpl" column="SupplierID" class="Supplier"/>
</class>

<class name="SupplierImpl" table="Suppliers" >
    <id name="SupplierID" type="int" unsaved-value="null" >
        <column name="SupplierID" sql-type="int identity" not-null="true" />
        <generator class="hilo" />
    </id>
    <set name="Products" table="Products" inverse="true" cascade="all">
        <key column="SupplierID" />
        <one-to-many column="ProductID" class="ProductImpl" />
    </set>
</class>



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