-->
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: Custom query/column never loading
PostPosted: Wed Mar 28, 2012 5:20 pm 
Newbie

Joined: Wed Mar 28, 2012 5:00 pm
Posts: 1
I have tried this two different ways now, as well as with two different versions of hibernate (3.5 and 3.6.10).

Code:
<class name="Preference" table="PREFERENCE" dynamic-update="true"
      dynamic-insert="true" select-before-update="true">
      <meta attribute="scope-class" inherit="false">public abstract</meta>
      <!-- implement HibernateObject for hibernate manipulation -->
      <meta attribute="implements" inherit="false">HibernateObject</meta>
      <meta attribute="extra-import" inherit="false">com.company.dem.obj.iface.HibernateObject</meta>

      <id name="id" type="int" unsaved-value="0">
         <meta attribute="use-in-equals">true</meta>
         <generator class="identity" />
      </id>

      <discriminator column="type" type="string" not-null="true" />

      <version name="version_id" unsaved-value="negative" type="int" />

      <property name="bundle" type="string" not-null="true" insert="false" update="false">
         <meta attribute="use-in-equals">true</meta>
         <column name="bundle" sql-type="string" />
      </property>
      <property name="name" type="string" not-null="true" insert="false" update="false">
         <meta attribute="use-in-equals">true</meta>
         <column name="name" sql-type="string" />
      </property>

      <property name="modified" type="timestamp" not-null="true">
         <meta attribute="property-type">java.sql.Timestamp</meta>
         <column name="modified" sql-type="datetime" />
      </property>
      <property name="user" type="string" not-null="true">
         <column name="user" sql-type="varchar" length="32" />
      </property>
      <property name="type" type="string" insert="false" update="false" />

      <subclass name="BooleanPreference" discriminator-value="boolean">
         <property name="value" type="boolean">
            <column name="boolean" sql-type="tinyint(1)" />
         </property>
         <property name="defaultValue" type="boolean" insert="false" update="false">
            <column name="defaultboolean" sql-type="tinyint(1)" />
         </property>
      </subclass>

      <subclass name="StringPreference" discriminator-value="string">
         <property name="value" type="string">
            <column name="string" sql-type="varchar" length="255" />
         </property>
         <property name="defaultValue" type="string" insert="false" update="false">
            <column name="defaultstring" sql-type="varchar" length="255" />
         </property>
      </subclass>
      
      <subclass name="EncryptedPreference" discriminator-value="encrypted">
         <property name="value" type="string">
            <column name="string" sql-type="varchar" length="255" read="aes_decrypt(unhex(string), 'testaes')" write="hex(aes_encrypt(?, 'testaes'))"/>
         </property>
         <property name="defaultValue" type="string" insert="false" update="false">
            <column name="defaultstring" sql-type="varchar" length="255"/>
         </property>
         
         <loader query-ref="getEncryptedByID"/>
         <!--
         <sql-insert>INSERT INTO preference (id, version_id, bundle, name, modified, user, type, string) VALUES(?, ?, ?, ?, ?, ?, ?, hex(aes_encrypt(?, "testaes")))</sql-insert>
         <sql-update>UPDATE preference SET version_id=?, modified=?, user=?, string=hex(aes_encrypt(?, "testaes")) WHERE id=? AND version_id=?</sql-update>
         <sql-delete>DELETE FROM preference WHERE id=?</sql-delete>
         -->
      </subclass>

      <subclass name="IntegerPreference" discriminator-value="numeral">
         <property name="value" type="int">
            <column name="numeral" sql-type="int(11)" />
         </property>
         <property name="defaultValue" type="int" insert="false" update="false">
            <column name="defaultnumeral" sql-type="int(11)" />
         </property>
      </subclass>
   </class>

   <sql-query name="getEncryptedByID" callable="true">
      <return alias="pref" class="com.company.dem.hibernate.EncryptedPreference"/>
      <![CDATA[
      SELECT
         id AS {pref.id},
         version_id AS {pref.version_id},
         bundle AS {pref.bundle},
         name AS {pref.name},
         modified AS {pref.modified},
         user AS {pref.user},
         type AS {pref.type},
         boolean,
         defaultboolean,
         aes_decrypt(unhex(string), "testaes") AS {pref.value},
         defaultstring AS {pref.defaultValue},
         numeral,
         defaultnumeral
      FROM
         preference
      WHERE
         id=?
      ]]>
   </sql-query>


I have the column transformer code loaded right now, and the class overrides commented out. Either setting will successfully override the insert/update methods, so the database will be written to with the hexed version of the encrypted string, however neither will successfully query the database correctly, so I am always getting the hexed string back, instead of it being "unhexed" and decrypted. Am I doing something wrong in the hbm.xml?


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.