-->
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.  [ 8 posts ] 
Author Message
 Post subject: Package mapping
PostPosted: Thu Feb 24, 2005 7:17 am 
Regular
Regular

Joined: Tue Oct 07, 2003 1:13 pm
Posts: 70
Location: Paris, France
I've found in an hibernate.cfg.xml example, the following line:

<mapping package="toto">

No doc about it, What does it mean ?

I've seen another example with the package keyword :

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

<hibernate-mapping package="toto">
<class name="Foo" table="FOO">
<id name="key" column="FOO_KEY" type="long">
<generator class="sequence">
<param name="sequence">FOO_GEN</param>

Can you explain a little bit ?

Thank you.
Richard


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 10:41 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
It defines a java-package namespace in effect for that <hibernate-mapping/>. Meaning, within that mapping declaration you do not need to fully qualify your domain class class-names *if* they are within that package.

Say I have a class with FQN "foo.Bar". In my mapping, I could either say:
Code:
<hibernate-mapping>
    <class name="foo.Bar">
        ...
    </class>
</hibernate-mapping>

- or -
Code:
<hibernate-mapping package="foo">
    <class name="Bar">
        ...
    </class>
</hibernate-mapping>


It also applies to assocation mappings. Say I also have "foo.Baz":
Code:
<hibernate-mapping package="foo">
    <class name="Baz">
        ...
        <many-to-one class="Bar" column="BAR_ID"/>
    </class>
</hibernate-mapping>

- instead of -
Code:
<hibernate-mapping>
    <class name="foo.Baz">
        ...
        <many-to-one class="foo.Bar" column="BAR_ID"/>
    </class>
</hibernate-mapping>


Its just a way to save typing


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 11:49 am 
Regular
Regular

Joined: Tue Oct 07, 2003 1:13 pm
Posts: 70
Location: Paris, France
Ok, I understand it as a convenient method but you didn't write about the following case :

<hibernate-configuration>
<session-factory>
<property name="connection.datasource">java:/comp/env/jdbc/annuaire</property>
<property name="dialect">org.hibernate.dialect.PostgreSQLDialect</property>
<property name="show_sql">false</property>

<mapping package="test"/>
<mapping class="test.Flight"/>
<mapping class="test.Sky"/>
<mapping class="test.Person"/>
<mapping class="test.animals.Dog"/>
</session-factory>
</hibernate-configuration>

What it the actual meaning of <mapping package="test"/> ? I bet it's annotation related ....


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 3:20 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
oh, sorry did not notice you were talking about the cfg.xml...

Yes, that tells Hibernate about a package containing annotated classes


Top
 Profile  
 
 Post subject: Re: Package mapping
PostPosted: Mon Feb 28, 2005 1:13 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
dharma wrote:
<mapping package="toto">

No doc about it, What does it mean ?

http://www.hibernate.org/hib_docs/annotations/

_________________
Emmanuel


Top
 Profile  
 
 Post subject: request further info on adding the package mapping
PostPosted: Fri Dec 15, 2006 11:45 am 
Newbie

Joined: Fri Dec 15, 2006 11:09 am
Posts: 10
Do I include the mapping package entry in the hibernate.cfg.xml only if I have a package level annotation (for example, a GenericGenerator)?

I did read this thread and the doc referred to in the last entry, and I see the example with a mapping package entry, but I do not see it say what that entry provides.

I was hoping that adding the mapping package entry meant that I do not have to add an individual mapping class entry for each annotated class within that package. This does not seem to be the case, and I am wondering if someone can confirm this.


Here is my config that works:

<?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>
<mapping resource="Class1_hbm.xml"/>
<mapping resource="Class2_hbm.xml"/>

<!-- list of annotated packages and classes -->
<mapping package="com.ieminc.example.domainobjects"/>
<mapping class="com.ieminc.example.domainobjects.Class3"/>
<mapping class="com.ieminc.example.domainobjects.Class4"/>
<mapping class="com.ieminc.example.domainobjects.Class5"/>

</session-factory>
</hibernate-configuration>


Here is my 'hoped for' config that does not work:

<?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>
<mapping resource="Class1_hbm.xml"/>
<mapping resource="Class2_hbm.xml"/>

<!-- list of annotated packages and classes -->
<mapping package="com.ieminc.example.domainobjects"/>
<!-- comment out classes that are in the package already specified -->
<!--<mapping class="com.ieminc.example.domainobjects.Class3"/>-->
<!--<mapping class="com.ieminc.example.domainobjects.Class4"/>-->
<!--<mapping class="com.ieminc.example.domainobjects.Class5"/>-->

</session-factory>
</hibernate-configuration>


In all examples I have seen on Hib site and in internet searching, there is always at least one class entry mapped within the package already mapped, which leads me to believe that my idea is wishful thinking.

Have just begun on Hib2 to Hib3 migration, and starting on Annotations. Go Hibernate!

Thank you,
Jeff


Top
 Profile  
 
 Post subject: Re: request further info on adding the package mapping
PostPosted: Sun Dec 17, 2006 6:48 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
jwood wrote:
I was hoping that adding the mapping package entry meant that I do not have to add an individual mapping class entry for each annotated class within that package. This does not seem to be the case, and I am wondering if someone can confirm this.


You are correct, this is not the case. I have clarified the wording in the documentation. What you ask for is not really useful since the archive is scanned for all @Entity classes anyway

_________________
Emmanuel


Top
 Profile  
 
 Post subject: thank you
PostPosted: Mon Dec 18, 2006 11:58 am 
Newbie

Joined: Fri Dec 15, 2006 11:09 am
Posts: 10
Emmanuel,

Thank you for the response and for mentioning the archive scan for @Entity classes. I was not aware of that and I am looking into that now. I appreciate it!

Jeff


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 8 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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.