[Hibernate-JIRA] Commented: (HHH-272) Add the ablity to use sql functions on generated insert/update
by Jason A.H. Mroz (JIRA)
[ http://opensource.atlassian.com/projects/hibernate/browse/HHH-272?page=co... ]
Jason A.H. Mroz commented on HHH-272:
-------------------------------------
Is there any movement on or workaround for this ticket? I need to use Oracle's SYSTIME and can't maintain sql-insert config for the number of tables involved.
> Add the ablity to use sql functions on generated insert/update
> --------------------------------------------------------------
>
> Key: HHH-272
> URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-272
> Project: Hibernate3
> Issue Type: New Feature
> Components: core
> Affects Versions: 3.1 rc3
> Environment: Hibernate3, Oracle9
> Reporter: Joe Dunne
> Priority: Minor
> Attachments: AbstractCollectionPersister.java, BasicEntityPersister.java, Column.java, HbmBinder.java, hibernate-mapping-3.0.dtd, Insert.java, SelectFragment.java, Update.java
>
>
> I would like to have Hibernate generate insert and update statements that contain a stored proc call.
> For example:
> insert into cat (id, name, tag) values ( ?, ? , encrypt(?) )
> Currently I have implemented the following:
> maping file:
> <property name="ssn" type="java.lang.String" access="field">
> <column name="SSN" scale="128" precision="0" not-null="false" sql-type="VARCHAR2" />
> </property>
> <property name="ssnDecrypted" formula="FNC_JAVA_DECRYPT(SSN)" type="java.lang.String" access="field"/>
> <sql-insert>insert into PARTICIPANT (VERSION, DATE_MODIFIED, DATE_CREATED, MODIFIED_BY, CREATED_BY, FIRST_NAME, LAST_NAME, PASSWORD, USERNAME, SSN, EMAIL, ID)
> values (?, ?, ?, ?, ?, ?, ?, ?, ?, FNC_JAVA_ENCRYPT(?), ?, ?)</sql-insert>
> <sql-update>update PARTICIPANT set VERSION=?, DATE_MODIFIED=?, DATE_CREATED=?, MODIFIED_BY=?, CREATED_BY=?, FIRST_NAME=?, LAST_NAME=?,
> PASSWORD=?, USERNAME=?, SSN = FNC_JAVA_ENCRYPT(?), EMAIL=? where ID=? and VERSION=?</sql-update>
> Domain Object:
> public String getSsn() {
> return ssnDecrypted;
> }
> public void setSsn(String ssn) {
> this.ssn = ssn;
> this.ssnDecrypted = ssn;
> }
> This works, but I would like to avoid the <sql-insert> and <sql-update> tags since the project I am on has multiple customer deployments. Each customer can specify what fields they want encrypted. It would be much easier to not have the deployment team write the sql for insert and update for each customer.
> Also, Java encryption is out. We have to do it in the database.
> The EnhancedUserType could support this - perhaps.
> public String getUpdateFragment() {
> return "encrypt(?)";
> }
> public String getInsertFragment() {
> return "encrypt(?)";
> }
> //Is this one possible too? This would avoid the double mapping
> //above and the magic in the domain object
> public String getSelectFragment(String columnName) {
> return "decrypt("+columnName+")";
> }
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 3 months
[Hibernate-JIRA] Created: (HHH-2598) Mapping a collection of entities from two different classes with the same collection name results in duplicate backref property exception if collection keys are not null
by Guido Scalise (JIRA)
Mapping a collection of entities from two different classes with the same collection name results in duplicate backref property exception if collection keys are not null
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Key: HHH-2598
URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2598
Project: Hibernate3
Issue Type: Bug
Components: core
Affects Versions: 3.2.3, 3.2.2, 3.2.1
Environment: Proven on Hibernate 3.2.2 and 3.2.3, PostgreSQL 8.2.3, WindowsXP, Java 1.5
Reporter: Guido Scalise
Attachments: backref.patch, Hibernate-bug.zip
Mapping a child entity collection from two different parent entities results in duplicate backref property exception when configuring the session factory if the collection keys are marked not null and the collection names are the same in both parents.
Log is:
(cfg.Environment 509 ) Hibernate 3.2.3
(cfg.Environment 542 ) hibernate.properties not found
(cfg.Environment 676 ) Bytecode provider name : cglib
(cfg.Environment 593 ) using JDK 1.4 java.sql.Timestamp handling
(cfg.Configuration 1426) configuring from resource: /hibernate.cfg.xml
(cfg.Configuration 1403) Configuration resource: /hibernate.cfg.xml
(cfg.Configuration 553 ) Reading mappings from resource : com/bbsw/tests/ParentA.hbm.xml
(cfg.HbmBinder 300 ) Mapping class: com.bbsw.tests.ParentA -> PARENT_A
(cfg.Configuration 553 ) Reading mappings from resource : com/bbsw/tests/ParentB.hbm.xml
(cfg.HbmBinder 300 ) Mapping class: com.bbsw.tests.ParentB -> PARENT_B
(cfg.Configuration 553 ) Reading mappings from resource : com/bbsw/tests/Child.hbm.xml
(cfg.HbmBinder 300 ) Mapping class: com.bbsw.tests.Child -> CHILD
(cfg.Configuration 1541) Configured SessionFactory: null
(cfg.HbmBinder 2375) Mapping collection: com.bbsw.tests.ParentA.children -> CHILD
(cfg.HbmBinder 2375) Mapping collection: com.bbsw.tests.ParentB.children -> CHILD
Exception in thread "main" org.hibernate.MappingException: Duplicate property mapping of _childrenBackref found in com.bbsw.tests.Child
at org.hibernate.mapping.PersistentClass.checkPropertyDuplication(PersistentClass.java:459)
at org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:449)
at org.hibernate.mapping.RootClass.validate(RootClass.java:192)
at org.hibernate.cfg.Configuration.validate(Configuration.java:1102)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1287)
at HBTest.main(HBTest.java:17)
The problem seems to be originated during the second Collection binding pass in org.hibernate.cfg.HbmBinder, as the Backrefs and IndexBackrefs names are created like this:
(Excerpts from HbmBinder.java r10921 2006-12-05 14:39:12Z steve.ebersole(a)jboss.com, contained in the Hibernate 3.2.3.ga source)
line 2242: IndexBackref ib = new IndexBackref();
line 2243: ib.setName( '_' + node.attributeValue( "name" ) + "IndexBackref" );
and
line 2478: Backref prop = new Backref();
line 2479: prop.setName( '_' + node.attributeValue( "name" ) + "Backref" );
in both cases the node name value is the collection name. So for every collection that points to a child, Hibernate creates a backref property without considering the posibility of more than one entity declaring the same collection name.
I've patched the code to add the collection owner's entity name to the property name, and it worked without problems.
I'm attaching:
* ParentA, ParentB and Child classes
* Mappings for ParentA, ParentB and Child
* hbm.xml file
* Main test case. (HBTest.java)
* Proposed patch in unified diff format.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
17 years, 3 months