-->
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: Incrementing an "Assigned" type ID
PostPosted: Mon Dec 12, 2005 12:23 pm 
Newbie

Joined: Wed Nov 30, 2005 3:45 pm
Posts: 10
Location: Vancouver. B.C.
Hi:

Can anyone provide me an example of incrementing the "id" when the mapping file has it defined as assigned? I'm having problems understanding the IncrementGenerator.generate() method and how this is used with the following mapping file and PO.

Thanks, Alex.

Hibernate version:
2.1.6

Mapping documents:

Code:
<hibernate-mapping>
    <class
        name="com.telus.ccs.adminRouting.model.po.SkillsetSiteAssociationAdmin
"
        table="SkillsetSiteAssociationAdmin"
        dynamic-update="false"
        dynamic-insert="false"
    >

        <id
            name="id"
            column="id"
            type="java.lang.Integer"
        >
            <generator class="assigned">
            </generator>
        </id>

        <property
            name="skillsetName"
            type="java.lang.String"
            update="false"
            insert="true"
            access="property"
            column="skillsetName"
            length="40"
            not-null="true"
        />

        <property
            name="siteName"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="siteName"
            length="30"
            not-null="true"
        />

        <property
            name="percentage"
            type="java.lang.Integer"
            update="true"
            insert="true"
            access="property"
            column="percentage"
            length="10"
            not-null="true"
        />

        <property
            name="phoneNumber"
            type="java.lang.String"
            update="true"
            insert="true"
            access="property"
            column="phoneNumber"
            length="11"
            not-null="true"
        />

        <property
            name="configName"
            type="java.lang.String"
            update="false"
            insert="true"
            access="property"
            column="configName"
            not-null="true"
        />

        <!--
            To add non XDoclet property mappings, create a file named
                hibernate-properties-SkillsetSiteAssociationAdmin.xml
            containing the additional properties and place it in your merge di
r.
        -->

    </class>

</hibernate-mapping>


Java PO:

Code:
public class SkillsetSiteAssociationAdmin extends BasePO {

    private static AppLogger logger = AppLogger.getLogger(
            SkillsetSiteAssociationAdmin.class);

        private Integer id;
        private String  skillsetName;
        private String  siteName;
        private Integer percentage;
        private String  phoneNumber;
        private String  configName;

        /**
         * @hibernate.id
         * generator-class="increment"
         */
        public Integer getId() {
                return this.id;
        }

        /**
         * @hibernate.property
         * not-null="true"
         * length="40"
         */
        public String getSkillsetName() {
                return this.skillsetName;
        }

        /**
         * @hibernate.property
         * not-null="true"
         * length="30"
         */
        public String getSiteName() {
                return this.siteName;
        }

        /**
         * @hibernate.property
         * not-null="true"
         * length="10"
         */
        public Integer getPercentage() {
                return this.percentage;
        }

        /**
         * @hibernate.property
         * not-null="true"
         * length="11"
         */
        public String getPhoneNumber() {
                return this.phoneNumber;
        }

        /**
         * @hibernate.property
         * not-null="true"
         * length="40"
         */
        public String getConfigName() {
                return this.configName;
        }

        public void setId(Integer id) {
                this.id = id;
        }

        public void setSkillsetName(String skillsetName) {
                this.skillsetName = skillsetName;
        }

        public void setSiteName(String siteName) {
                this.siteName = siteName;
        }

        public void setPercentage(Integer percentage) {
                this.percentage = percentage;
        }

        public void setPhoneNumber(String phoneNumber) {
                this.phoneNumber = phoneNumber;
        }

        public void setConfigName (String configName) {
                this.configName = configName;
        }
}

Code between sessionFactory.openSession() and session.close():
n/a
Full stack trace of any exception that occurs:
n/a
Name and version of the database you are using:
Oracle 9
The generated SQL (show_sql=true):
n/a
Debug level Hibernate log excerpt:


Top
 Profile  
 
 Post subject: mapping
PostPosted: Mon Dec 12, 2005 1:29 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
IncementGenerator.generate() method is not used by the mapping. I guess the annotations in the class file are for XDoclet, but I am afraid that it did not do a very good job in this case.

Assigned means that our code have to take care of assigning ID to object and calling appropriate method (save() or update()) to persist the object.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


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.