Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: getHibernateTemplate().get(...) problem

  1. #1
    Join Date
    Nov 2005
    Location
    Lille-FRANCE
    Posts
    21

    Default getHibernateTemplate().get(...) problem

    Hello, i have a problem with the getHibernateTemplate().get(...) Method.

    Here is my mapping :
    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">
    <hibernate-mapping>
    	<class name="com.auchan.protoFwk27.metier.fournisseur.internal.FournisseurImpl" table="P2_5_FOURNISSEUR">
    		<id column="IFLS" name="ifls">
    			<generator class="assigned"/>
    		</id>
    		<property column="LIBELLE" name="libelle" not-null="true"/>
    	</class>
    </hibernate-mapping>
    My object FournisseurImpl implements an interface named Fournisseur so I can make HQL on the interface (see below the working code using Criteria)

    Here is what i try to do :
    Code:
    Fournisseur fournisseur = (Fournisseur) getHibernateTemplate().get(Fournisseur.class, idFournisseur);
    i throw me :
    Code:
    org.hibernate.MappingException: Unknown entity: com.auchan.protoFwk27.metier.fournisseur.Fournisseur
    this code works :

    Code:
    //Use of Criteria
    List myList = null;
    DetachedCriteria detachedCriteria = DetachedCriteria.forClass(Fournisseur.class);
    detachedCriteria.add(Restrictions.eq("ifls", idFournisseur));
    myList = getHibernateTemplate().findByCriteria(detachedCriteria);
    Fournisseur fournisseur = (Fournisseur) myList.get(0);
    Other code working :
    Code:
    List lstFrn = getHibernateTemplate().loadAll(Fournisseur.class);
    I don't understand why the getHibernateTemplate().get(...) does not work. May be it's normal ???
    >> Thieum.

  2. #2
    Join Date
    Dec 2005
    Posts
    269

    Default

    is the load() working?

  3. #3
    Join Date
    Nov 2005
    Location
    Lille-FRANCE
    Posts
    21

    Default

    No, the load does not work. I have exactly the same exception.

    version information :
    spring 2.0.2
    hibernate : 3.0.2
    >> Thieum.

  4. #4
    Join Date
    Dec 2005
    Posts
    269

    Default

    what if you put
    Code:
    Fournisseur fournisseur = (Fournisseur) getHibernateTemplate().get(FournisseurImpl.class, idFournisseur);

  5. #5
    Join Date
    Nov 2005
    Location
    Lille-FRANCE
    Posts
    21

    Default

    Yes, it works. I tried it but forgot do talk about.
    >> Thieum.

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    Do you need to specify the proxyInterface for the class? I've never tried this but the reference manual actually shows an example loading the Impl.
    http://www.hibernate.org/hib_docs/v3...laration-class
    http://www.hibernate.org/hib_docs/v3...tching-proxies
    Last edited by karldmoore; Feb 28th, 2007 at 11:39 AM.

  7. #7
    Join Date
    Nov 2005
    Location
    Lille-FRANCE
    Posts
    21

    Default

    I try but it does not work
    >> Thieum.

  8. #8
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    I'm not sure you can load it by the interface. If you have a look at the reference manual even that uses the Impl.
    Code:
    Cat cat = (Cat) session.load(CatImpl.class, catid);
    Iterator iter = session.iterate("from CatImpl as cat where cat.name='fritz'");
    Cat fritz = (Cat) iter.next();
    http://www.hibernate.org/hib_docs/v3...tching-proxies

  9. #9
    Join Date
    Dec 2005
    Posts
    269

    Default

    AFAIK, you must use the classes rather that interfaces in HQL-queries.
    The interfaces (in mappings) can be used only as proxies to control lazy-loading strategy and they don't replace the need to specify classes.
    I also don't really understand, why use interfaces in regard to POJOs... What implementation details can you hide behind an interface for a bean with no behaviour?

  10. #10
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,425

    Default

    Quote Originally Posted by Injecteer View Post
    AFAIK, you must use the classes rather that interfaces in HQL-queries.
    The interfaces (in mappings) can be used only as proxies to control lazy-loading strategy and they don't replace the need to specify classes.
    Indeed. I've never actually tried this before, but I did last night and found the above to be true. The load(..), get(..), HQL, etc...... require the actual class name rather than the interface. I don't really think this is a major problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •