From: <sco...@jb...> - 2005-08-03 04:18:15
|
What about a multi-session embedded mode. The Mappings attribute would be an HibernateMapping[] array object (something you may need to create) that is umarshalled from the xml based on the jbossxb schema mappings applied in the hibernate-mapping-3.0.xsd: | <mbean code="org.jboss.hibernate.har.HARDeployer" name="jboss.har:service=HARDeployer"> | <attribute name="Mappings" serialDataType="jbxb"> | <hbm:mappings | xmlns:xs="http://www.w3.org/2001/XMLSchema-instance" | xmlns:hbm="urn:jboss:hibernate-mapping" | xs:schemaLocation="urn:jboss:hibernate-mapping hibernate-mapping-3.0.xsd" | > | <hibernate-mapping package="org.jboss.test.hibernate.model"> | | <!-- there is no "Edit Role" function, so map Role as an immutable class --> | <class name="Role" table="t_role" mutable="false"> | | <!-- there are few roles, and they are not updated so cache them --> | <cache usage="read-only"/> | | <id name="id" type="long" unsaved-value="null"> | <generator class="increment"/> | </id> | | <property name="name" unique="true" not-null="true" update="false" length="25"/> | <property name="description" length="150"/> | <property name="timeOfCreation" update="false" not-null="true"/> | | <!-- | this is the "inverse" association of the User.userRoles collection. This | mapping demonstrates that an "inverse" end of a many-to-many does not need | to be the same type of collection mapping as the other end! | --> | <bag name="users" lazy="true" table="t_user_role" inverse="true" order-by="timeOfCreation asc"> | <!-- the foreign key of the Role --> | <key column="role_id"/> | <!-- the foreign key of the User --> | <many-to-many column="user_id" class="User" outer-join="true"/> | <!-- Since Users are not cached, make sure we use an outer join! --> | </bag> | | </class> | | | | <!-- A named HQL query. This uses a subquery, so it won't | work on MySQL! --> | | <query name="unassignedRolesByUser.HQL"> | <![CDATA[ | from Role role | where not :user in ( select u.id from role.users u ) | order by role.name desc | ]]> | </query> | | | <!-- For MySQL 4.0, which has no support for subselects, we | need to use an ON-clause condition which is not provided | by HQL. So we will use a named SQL query instead. --> | | <sql-query name="unassignedRolesByUser.MySQL"> | <![CDATA[ | select {rol.*} | from t_role rol | left join t_user_role ur | on ur.role = rol.id and ur.user = :user | where ur.id is null | order by rol.name desc | ]]> | <return alias="rol" class="Role"/> | <synchronize table="t_user_role"/> | </sql-query> | | | </hibernate-mapping> | <hibernate-mapping package="org.jboss.test.hibernate.model"> | | <class name="User" table="t_user"> | | <id name="id" type="long" unsaved-value="null"> | <generator class="increment"/> | </id> | | <!-- Use a timestamp for optimistic locking --> | <version name="timeOfLastUpdate" type="calendar"/> | | <!-- We don't change the handle, so map it with update="false". --> | <property name="handle" unique="true" not-null="true" update="false"/> | | <!-- password is a keyword in some databases, so quote it --> | <property name="password" column="`password`" not-null="true"/> | | <property name="email"/> | | <!-- We can't change the creation time, so map it with update="false". --> | <property name="timeOfCreation" update="false" not-null="true"/> | | <!-- Mapping for the component class Name --> | <component name="name"> | <property name="firstName"/> | <!-- initial is a keyword in some databases, so quote it --> | <property name="initial" column="`initial`"/> | <property name="lastName"/> | </component> | | <!-- | A many-to-many association modelled using a composite-element mapping | (this lets us keep track of the time of creation for the link. We use an | <idbag>, since that gives us a nice surrogate key. | --> | <idbag name="userRoles" lazy="true" table="t_user_role" order-by="timeOfCreation asc" cascade="save-update"> | <!-- the surrogate primary key --> | <collection-id column="id" type="long"> | <generator class="increment"/> | </collection-id> | <!-- the foreign key of the User --> | <key column="user"/> | <!-- | a composite-element holding the associated Role and User, and the | creation time of the link | --> | <composite-element class="UserRole"> | <!-- for convenience, a backpointer to the User --> | <parent name="user"/> | <!-- an "extra" column --> | <property name="timeOfCreation"/> | <!-- the foreign key of the Role --> | <many-to-one name="role" cascade="save-update" outer-join="false"/> | <!-- since Roles are cached, disable outerjoining! --> | </composite-element> | </idbag> | | <!-- | Usually, when we access the user's roles, we don't care about the creation | time of the link, etc. - we just want the roles themselves. So we map | another collection to the same table. This demonstrates how inverse="true" | can be used for purposes other than modelling a bi-directional association! | --> | <bag name="roles" lazy="true" table="t_user_role" inverse="true" order-by="timeOfCreation asc" cascade="save-update" batch-size="9"> | <!-- we access this collection often, so cache it. --> | <cache usage="transactional"/> | <!-- the foreign key of the User --> | <key column="user_id"/> | <!-- the foreign key of the Role --> | <many-to-many column="role_id" class="Role" outer-join="false"/> | <!-- since Roles are cached, disable outerjoining! --> | </bag> | | <!-- | A simple collection of values. This collection table has a composite | primary key consisting of the user and password columns. | --> | <set name="previousPasswords" table="t_old_passwords" lazy="true"> | <!-- the foreign key of the User--> | <key column="user_id"/> | <!-- the element (of value type) --> | <element type="string" column="pswd"/> | </set> | | </class> | | </hibernate-mapping> | </hbm:mappings> | </attribute> | </mbean> | View the original post : http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3888090#3888090 Reply to the post : http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3888090 |