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.  [ 1 post ] 
Author Message
 Post subject: Update Map table
PostPosted: Tue Aug 25, 2009 7:14 am 
Newbie

Joined: Tue Aug 25, 2009 6:34 am
Posts: 1
Hello Everyone,

I have a class with a map inside, the primary key for the map table (Offering) is the issuerId and currency but when updating the offering table it first deletes the current record and then inserts a new one (Any way of forcing and update instead of delete and insert?).
The problem is it deletes by issuerId instead of issuerId and currency. It only allows me to a single currency istead of several for each issuerId
I tried adding a where clause to the map where="currency=?" but I wasn't abble to pass a parameter to specify the currency.

**************Hibernate Queries ********
Code:
delete from Offering where issuerId=23

insert into Offering (issuerId, currency, yield1W, yield2W, yield3W, yield1M, yield2M, yield3M, yield4M, yield5M, yield6M, yield9M, yield12M, last_Updated) values (23, 'USD', '', '', '', '', '', '', '', '', '', '', '', '2009-08-25 11:45:35.328')

************* Issuer.hbm.xml ****
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 package="..."  >
   <class name="Issuer" table="Issuer" dynamic-insert="true" dynamic-update="true" >
      <id name="id" column="issuerId">
         <generator class="native"/>
      </id>
   [color=#4040FF]   <!-- <timestamp name="lastUpdatedDatetime" column="last_Updated" unsaved-value="null" /> -->[/color]
      <property name="bloombergTicker" type="string" not-null="true" unique="true" update="false"/>
      <property name="name"  type="string" not-null="true" update="false" />
      <property name="sAndpRating" type="string" not-null="true" update="false" />
      <property name="moodyRating" type="string" not-null="true" update="false" />
      <property name="productType" type="string" not-null="true" update="false" />
      <property name="sector" type="string" not-null="true" update="false" />
      <property name="lastUpdatedDatetime" column="last_Updated" not-null="false" />
      
      <map name="offerings" table="Offering" lazy="false">
         <key foreign-key="FK_Offering_Issuer" unique="false">
            <column name="issuerId" unique="false" ></column>            
         </key>
         <composite-map-key class="Currency">
            <key-property name="name" column="currency" ></key-property>
         </composite-map-key>
[color=#4040FF]         <!--<map-key type="string">
            <column name="currency" unique="false"></column>
         </map-key>-->[/color]
         <composite-element class="Offerings" >
            <property name="yield1W" type="big_decimal" length="10"/>
            <property name="yield2W" type="big_decimal" length="10"/>
            <property name="yield3W" type="big_decimal" length="10"/>
            <property name="yield1M" type="big_decimal" length="10"/>
            <property name="yield2M" type="big_decimal" length="10"/>
            <property name="yield3M" type="big_decimal" length="10"/>
            <property name="yield4M" type="big_decimal" length="10"/>
            <property name="yield5M" type="big_decimal" length="10"/>
            <property name="yield6M" type="big_decimal" length="10"/>
            <property name="yield9M" type="big_decimal" length="10"/>
            <property name="yield12M" type="big_decimal" length="10"/>            
            <property name="lastUpdatedDatetime" insert="false" update="false" column="last_Updated" type="timestamp" generated="always" />
         </composite-element>         
         
[color=#4040FF]         
                                      <!--<filter name="myCurrency" condition=":myCurrencyParam = currency"/>   -->
          <!-- <where="currency=?"-->[/color]
      </map>      
   </class>

[color=#4040FF]   <!--<filter-def name="myCurrency">
      <filter-param name="myCurrencyParam" type="String"/>
   </filter-def>-->[/color]
</hibernate-mapping>

***********Hibernate.cfg.xml **************

Code:
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
   <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="..." />
        <property name="url" value="....." />
        <property name="username" value="..." />
        <property name="password" value="..." />
    </bean>
   
    <bean id="p6spy" class="com.p6spy.engine.spy.P6DataSource" destroy-method="close">
       <constructor-arg>
          <ref local="dataSource" />
       </constructor-arg>
    </bean>   

    <!-- Hibernate SessionFactory -->
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="p6spy" />
        <!-- <property name="dataSource" ref="dataSource" /> -->
        <property name="mappingResources">
            <list>
                <value>.../Issuer.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">...</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
        </props>
        </property>
    </bean>
   
    <!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA)-->
    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>

    <bean id="IssuerDao" class=".....server.dao.impl.IssuerDaoHibernateImpl">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>

    <bean id="OfferingDao" class=".....server.dao.impl.OfferingDaoHibernateImpl">
        <property name="sessionFactory"><ref local="sessionFactory"/></property>
    </bean>
       
</beans>

*****************AppContext.xml ***

Code:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

   <bean id="issuerService" class="....server.services.IssuerServiceImpl">
      <property name="issuerDao" ref="issuerDaoTest" />      
   </bean>
   
   <bean id="issuerDaoTest" class=".....server.dao.impl.IssuerDaoHibernateImpl">
      <property name="sessionFactory" ref="sessionFactory" />
   </bean>
   
   <bean id="offeringDaoTest" class="......server.dao.impl.OfferingDaoHibernateImpl">
      <property name="sessionFactory" ref="sessionFactory" />
   </bean>

   <bean id="offeringService" class=".......server.services.OfferingServiceImpl">
      <property name="offeringDao" ref="offeringDaoTest" />
      <property name="issuerService" ref="issuerService"  />
   </bean>      
</beans>

****************

Many Regards,
Matarelio


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.