NHibernate.Evers

43 views
Skip to first unread message

Fabio Maulo

unread,
Mar 2, 2010, 9:44:03 AM3/2/10
to nhc...@googlegroups.com
Hi all.
Simon Duduica will work on the port of NHibernate.Evers.

Simon please introduce yourself a bit and overall few words about the roadmap of the porting.

Tuna may help you a bit because he have some work done about NH Evers.

Welcome Simon.

--
Fabio Maulo

Scott White

unread,
Mar 2, 2010, 10:28:02 AM3/2/10
to nhc...@googlegroups.com
I'm curious about this feature.  Do you mean Envers?  For entity auditing?

--
You received this message because you are subscribed to the Google Groups "NHibernate Contrib - Development Group" group.
To post to this group, send email to nhc...@googlegroups.com.
To unsubscribe from this group, send email to nhcdevs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhcdevs?hl=en.

Jason Dentler

unread,
Mar 2, 2010, 3:05:47 PM3/2/10
to nhc...@googlegroups.com
This is great news! 

On Tue, Mar 2, 2010 at 8:44 AM, Fabio Maulo <fabio...@gmail.com> wrote:

Simon Duduica

unread,
Mar 3, 2010, 4:45:14 AM3/3/10
to NHibernate Contrib - Development Group
Hello everybody and thanks for the welcome,

Well, firs about me: I'm a software engineer, 33, I live in Bucharest,
Romania and I work for a software company where I am employed as a
Project Manager but I also do a lot of technical stuff especially in
the initiation phase of projects.

The project I'm currently starting at work will be developed in .NET
with NHibernate and some of the required features would be best served
by a bi-temporal data versioning library that exists for Hibernate in
Java and as you know it's called Envers. So we decided that the best
approach would be to port Envers to NHibernate.

As for the roadmap, will start by porting in the next two months the
CUD part (AuditEventListener class and its dependencies) that is
needed in the first phase of the project.
In the second phase that starts in August 2010 will also port the
query and the reader part.

Tuna, can you please tell us about your work on NH Envers?

Simon.

Fabio Maulo

unread,
Mar 3, 2010, 9:45:51 AM3/3/10
to nhc...@googlegroups.com
Perhaps even Jason Dentler may have something to say ;)

2010/3/3 Simon Duduica <simo...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "NHibernate Contrib - Development Group" group.
To post to this group, send email to nhc...@googlegroups.com.
To unsubscribe from this group, send email to nhcdevs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhcdevs?hl=en.




--
Fabio Maulo

Jason Dentler

unread,
Mar 3, 2010, 12:50:47 PM3/3/10
to nhc...@googlegroups.com
Haha. Tuna would be a better source. My attempt is a new creation, not a port of Envers. 

Tuna Toksoz

unread,
Mar 6, 2010, 3:24:47 PM3/6/10
to nhc...@googlegroups.com
Hi everybody,

Sorry for very late reply.
If you're using Google Talk, we can talk there. Or we can have Wave (is it still alive?) session so that Me, Jason and Simon can discuss.


Tuna Toksöz
Eternal sunshine of the open source mind.

http://devlicio.us/blogs/tuna_toksoz
http://tunatoksoz.com
http://twitter.com/tehlike

Fabio Maulo

unread,
Mar 6, 2010, 3:45:54 PM3/6/10
to nhc...@googlegroups.com
Only those 3 guys ? :( 

Nobody loves me, nobody loves me enough, Enough to save me, oh no :((

2010/3/6 Tuna Toksoz <teh...@gmail.com>



--
Fabio Maulo

Tuna Toksoz

unread,
Mar 6, 2010, 3:46:55 PM3/6/10
to nhc...@googlegroups.com
lol :) You are the "supervisor" :) You are implicitly in all meetings. We don't need to explicitly invite you :)

Tuna Toksoz

unread,
Mar 6, 2010, 3:47:36 PM3/6/10
to nhc...@googlegroups.com
Actually, if it is Wave, everybody is invited :)
On Sat, Mar 6, 2010 at 10:45 PM, Fabio Maulo <fabio...@gmail.com> wrote:

Simon Duduica

unread,
Mar 10, 2010, 5:44:02 AM3/10/10
to NHibernate Contrib - Development Group
Hi Tuna,

Wave would be interesting!
In the meanwhile, I started porting the AuditEventListener and
depending classes and I have questions:

1. I found in AuditSync a call to
org.hibernate.engine.SessionFactoryImplementor.openTemporarySession()
that I don't find in the ISessionFactoryImplementor on NHibernate.
While writing this question :), looking in the code, I figured out
it's equivalent to OpenSession(null, false,false,
ConnectionReleaseMode.AfterStatement); Is this correct?

2. There are refferences to java annotations as @Entity, @Version,
@MapKey. How should these be treated?

Simon.

Simon Duduica

unread,
Mar 22, 2010, 8:15:29 AM3/22/10
to NHibernate Contrib - Development Group
Hey, any answer at all would be greatly appreciated!

I got over point 1., 2 is still actual and now I got stuck in the
following problem: The xml mapping document for Envers needs some
added attributes for the tag key-property (insert and update, both
bool) and for key-many-to-one (type), but the schema validation fails
because of these added properties in
NHibernate.Cfg.XmlHbmBinding.Binder.Deserialize[T](XmlNode node)

This is the mapping:

<hibernate-mapping assembly="Envers.NET" xmlns="urn:nhibernate-
mapping-2.2" auto-import="false">
<class entity-name="Envers.Net.Model.Address_AUD"
table="Address_AUD">
<composite-id name="originalId">
<key-property name="id" insert="true" update="false"
type="SimpleValue">
<column name="id" length="255" scale="2" precision="19" />
</key-property>
<key-many-to-one type="integer"
class="NHibernate.Envers.DefaultRevisionEntity" name="REV">
<column name="REV" />
</key-many-to-one>
</composite-id>
<property name="REVTYPE" insert="true" update="false"
type="NHibernate.Envers.Entities.RevisionTypeType" />
</class>
</hibernate-mapping>

The first option seems to add the attributes to tne hibernate-
mapping.xsd schema. What do you think?

Tuna Toksoz

unread,
Mar 22, 2010, 10:07:44 AM3/22/10
to nhc...@googlegroups.com
Sorry Simon,

I am sorry, i just missed this email.

1. I don't know about AuditSync, my port was incomplete and i think i didn't get into that class yet.
2. Annotations are for EntityManager (of JPA). They are used for mapping entities, just like XML.

For Envers configuration, I was planning to discard XML configuration completely, and only have fluent interface. Makes things a lot easier, and also harder at the same time.

Please let me know if you need anything else.



Tuna Toksöz
Eternal sunshine of the open source mind.

http://devlicio.us/blogs/tuna_toksoz
http://tunatoksoz.com
http://twitter.com/tehlike




Jason Dentler

unread,
Mar 22, 2010, 3:35:04 PM3/22/10
to nhc...@googlegroups.com
I'd prefer something convention-based and user-configurable like Fabio has done with ConfORM. That's the approach I had in mind. Attributes smell, and I believe the XSD has been the same for a while now, so best not to change it if possible. 

My two cents,
Jason

Tuna Toksoz

unread,
Mar 22, 2010, 3:59:26 PM3/22/10
to nhc...@googlegroups.com
This is why i love programmatic/fluent way. it can be done using conventions, too!

Simon Duduica

unread,
Mar 23, 2010, 12:08:48 PM3/23/10
to nhc...@googlegroups.com

Can you or Fabio give me some example or precise place where to look for this kind of solution?

Simon Duduica

unread,
Mar 23, 2010, 12:15:16 PM3/23/10
to nhc...@googlegroups.com
And now another problem I falled onto:

For an audited entity say Address, Envers creates an associated table Address_AUD to store the revisions. The table is mapped using Hibernate even if there is no real class Address_AUD to map to. My port throws an error due to two differences I found, for my mapping that i posted before:

1. ClassCompositeIdBinder.BindComponent sets IsEmbeded = true while in Java the equivalent HbmBinder.bindComponent calls setDynamic(true)

2. Later on, in ClassCompositeIdBinder.BindComponent, when it calls CreateProperty it tries to pass compositeId.ComponentClass and the getter throws a MappingException because componentClass is null and the Component is not Dynamic.

Can you please advice on what should I do in this situation? Any help greatly appreciated!

Ayende Rahien

unread,
Mar 23, 2010, 4:00:09 PM3/23/10
to nhc...@googlegroups.com
Is the code available somewhere?

--

Fabio Maulo

unread,
Mar 23, 2010, 7:04:43 PM3/23/10
to nhc...@googlegroups.com
I have ported the DTD to XSD
This is the DTD chunk of Hibernate 3.3.1
<!ELEMENT key-property (meta*,column*,type?)>
<!ATTLIST key-property name CDATA #REQUIRED>
<!ATTLIST key-property access CDATA #IMPLIED>
<!ATTLIST key-property type CDATA #IMPLIED>
<!ATTLIST key-property column CDATA #IMPLIED>
<!ATTLIST key-property length CDATA #IMPLIED>
<!ATTLIST key-property node CDATA #IMPLIED>

<!-- A many-to-one association embedded in a composite identifier or map index 
(always not-null, never cascade). -->

<!ELEMENT key-many-to-one (meta*,column*)>
<!ATTLIST key-many-to-one name CDATA #REQUIRED>
<!ATTLIST key-many-to-one access CDATA #IMPLIED>
<!ATTLIST key-many-to-one class CDATA #IMPLIED>
<!ATTLIST key-many-to-one entity-name CDATA #IMPLIED>
<!ATTLIST key-many-to-one column CDATA #IMPLIED>
<!ATTLIST key-many-to-one foreign-key CDATA #IMPLIED>
<!ATTLIST key-many-to-one lazy (false|proxy) #IMPLIED>

As you can see there isn't neither "insert" nor "update"...
perhaps it is because we are talking about the PK and an "insert=false" in the PK is something at least strange.

If you really need it we can change the XSD in NH-Core but I need to check how Hibernate is managing an "insert=false" in a PK column.

2010/3/22 Simon Duduica <simo...@gmail.com>
--
You received this message because you are subscribed to the Google Groups "NHibernate Contrib - Development Group" group.
To post to this group, send email to nhc...@googlegroups.com.
To unsubscribe from this group, send email to nhcdevs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhcdevs?hl=en.




--
Fabio Maulo

Simon Duduica

unread,
Mar 24, 2010, 3:22:29 AM3/24/10
to nhc...@googlegroups.com
Ayende, the code is not yet posted as till two days ago would not even compile :).
My plan was to post it either when the smoke tests pass (that is being able to create the session factory and persist an audited entity) either when someone requests it - whichever comes first - so second condition is met and I will post it on NHContrib SVN later on today.

Ayende Rahien

unread,
Mar 24, 2010, 3:28:10 AM3/24/10
to nhc...@googlegroups.com
Cool

On Wed, Mar 24, 2010 at 9:22 AM, Simon Duduica <simo...@gmail.com> wrote:
Ayende, the code is not yet posted as till two days ago would not even compile :).
My plan was to post it either when the smoke tests pass (that is being able to create the session factory and persist an audited entity) either when someone requests it - whichever comes first - so second condition is met and I will post it on NHContrib SVN later on today.

Simon Duduica

unread,
Mar 24, 2010, 3:29:57 AM3/24/10
to nhc...@googlegroups.com
Fabio, this is also what I saw in the Hibernate DTD, on the other hand Hibernate does not complain about the newly added attributes. I use a java project for comparison (Hibernate + Envers + Spring), that has the same unit tests as the .NET project and the Java Hibernate mapping generated is the following:

<?xml version="1.0" encoding="UTF-8"?>
<hibernate-mapping auto-import="false">
    <class entity-name="ro.siveco.apdrp.envers.model.Person_AUD" table="Person_AUD">
        <composite-id name="originalId">
            <key-property name="id" insert="true" update="false" type="long">

                <column name="id" length="255" scale="2" precision="19"/>
            </key-property>
            <key-many-to-one type="integer" class="org.hibernate.envers.DefaultRevisionEntity" name="REV">

                <column name="REV"/>
            </key-many-to-one>
        </composite-id>
        <property name="REVTYPE" insert="true" update="false" type="org.hibernate.envers.entities.RevisionTypeType"/>
        <property name="firstName" insert="true" update="false" type="string"><column name="firstName" length="255" scale="2" precision="19"/></property><property name="lastName" insert="true" update="false" type="string">
            <column name="lastName" length="255" scale="2" precision="19"/>
        </property>
    </class>
</hibernate-mapping>

The name of the entity that I gave as example is different as I have more entities in the java project but the case is the same.
I will try to post also the java project if you think it's of any help.


Fabio Maulo

unread,
Mar 24, 2010, 7:47:46 AM3/24/10
to nhc...@googlegroups.com
I have understood the mapping.
What I would know is : who will manage "insert"/"update" tags of key-property ?

2010/3/24 Simon Duduica <simo...@gmail.com>


--
You received this message because you are subscribed to the Google Groups "NHibernate Contrib - Development Group" group.
To post to this group, send email to nhc...@googlegroups.com.
To unsubscribe from this group, send email to nhcdevs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhcdevs?hl=en.



--
Fabio Maulo

Fabio Maulo

unread,
Mar 24, 2010, 7:49:48 AM3/24/10
to nhc...@googlegroups.com
Why you can commit your work day by day, step by step ?

2010/3/24 Simon Duduica <simo...@gmail.com>
Ayende, the code is not yet posted as till two days ago would not even compile :).
My plan was to post it either when the smoke tests pass (that is being able to create the session factory and persist an audited entity) either when someone requests it - whichever comes first - so second condition is met and I will post it on NHContrib SVN later on today.

--
You received this message because you are subscribed to the Google Groups "NHibernate Contrib - Development Group" group.
To post to this group, send email to nhc...@googlegroups.com.
To unsubscribe from this group, send email to nhcdevs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhcdevs?hl=en.



--
Fabio Maulo

Simon Duduica

unread,
Mar 25, 2010, 11:48:12 AM3/25/10
to NHibernate Contrib - Development Group
I've commited in sandbox/simondud today after two failed tries
yesterday.
I will commit every day from now on if I have changes.

Simon.

Simon Duduica

unread,
Apr 1, 2010, 11:10:42 AM4/1/10
to nhc...@googlegroups.com
Fabio, what do you think about this problem? Thanks!

Simon Duduica

unread,
Apr 13, 2010, 4:31:15 AM4/13/10
to NHibernate Contrib - Development Group
Just to let you know, I'm still looking for a solution of the
following problem:

For an audited entity say Address, Envers creates an associated table
Address_AUD to store the revisions. The table is mapped using
Hibernate even
if there is no real class Address_AUD to map to. My port throws an
error due
to two differences I found, for my mapping that i posted before:

1. ClassCompositeIdBinder.BindComponent sets IsEmbeded = true while in
Java
the equivalent HbmBinder.bindComponent calls setDynamic(true)

2. Later on, in ClassCompositeIdBinder.BindComponent, when it calls
CreateProperty it tries to pass compositeId.ComponentClass and the
getter
throws a MappingException because componentClass is null and the
Component
is not Dynamic.

For now the solution I see is to modify myself the NHibernate code,
test and send you
the patch. Do you have any other sugestion? Any help greatly
appreciated!

Fabio Maulo

unread,
May 1, 2010, 12:32:42 AM5/1/10
to nhc...@googlegroups.com
If the patch pass all NH's core tests, please point me to the issue or send me the patch in my private mail I'll commit it ASAP.

P.S. sorry for the delay...

--
You received this message because you are subscribed to the Google Groups "NHibernate Contrib - Development Group" group.
To post to this group, send email to nhc...@googlegroups.com.
To unsubscribe from this group, send email to nhcdevs+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhcdevs?hl=en.




--
Fabio Maulo

Simon Duduica

unread,
Jun 28, 2010, 11:56:13 AM6/28/10
to NHibernate Contrib - Development Group
Hi everybody,

I have news regarding Envers.NET. I've commited a version that works
in basic tests for CUD operations, with entities that have
relationships between them, also with entities that are not audited.
To make things work I had to make two small modifications of
NHibernate, both modifications were tested running all NHibernate unit
tests and they all passed. I already sent the first modification to
Fabio and the second I will send this evening.
I would like to thank Tuna for helping me out with good advices when I
was stuck :)

Tuna Toksoz

unread,
Jun 28, 2010, 12:00:30 PM6/28/10
to nhc...@googlegroups.com
Wohoo! Congrats! you make my dreams come true :)

--

Jason Dentler

unread,
Jun 28, 2010, 12:09:46 PM6/28/10
to nhc...@googlegroups.com
Congratulations Simon! This is awesome news! 

- Jason

Simon Duduica

unread,
Sep 21, 2010, 8:49:46 AM9/21/10
to nhc...@googlegroups.com
I commited new changes to Envers that fix the query of entities at revision. Now it's possible to obtain an entity at revision with the corresponding related entities (at same revision). Next step will be to make it work with NH3.
Many thanks to Roger Kratz who kindly helped me out of an annoying bug :)
Reply all
Reply to author
Forward
0 new messages