Envers with a PrimitiveType

182 views
Skip to first unread message

Patrick

unread,
Mar 21, 2012, 2:28:14 PM3/21/12
to nhu...@googlegroups.com
I'm trying to get Envers up and running in my project (based on S#arp Lite) and am having trouble getting it to work with a custom PrimitiveType.  Basically, I using the Enumeration class from Jimmy Bogard's site:
http://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/

and tying it into nHibernate with an EnumerationType<T> that inherits from PrimitiveType.  That code is mostly stolen from:
http://code.google.com/p/codecampserver/source/browse/trunk/src/Infrastructure.NHibernate/DataAccess/EnumerationType.cs?r=1063

My nHibernate mapping for a simple property like this is:
    map.Property(x => x.Type,
        pm =>
        {
            pm.Type<EnumerationType<CourseType>>();
            pm.Column("CourseTypeFk");
        });

However, Envers doesn't seem to be able to deal with it.  I just want it to treat it as its associated primitive type (int) but I'm getting the following exception:

NHibernate.MappingException was unhandled by user code
  Message=Could not determine type for: Enumeration, NHibernate.Envers, for columns: NHibernate.Mapping.Column(CourseTypeFk)
  Source=NHibernate
  StackTrace:
       at NHibernate.Mapping.SimpleValue.get_Type()
       at NHibernate.Mapping.SimpleValue.IsValid(IMapping mapping)
       at NHibernate.Mapping.Property.IsValid(IMapping mapping)
       at NHibernate.Mapping.PersistentClass.Validate(IMapping mapping)
       at NHibernate.Mapping.RootClass.Validate(IMapping mapping)
       at NHibernate.Cfg.Configuration.ValidateEntities()
       at NHibernate.Cfg.Configuration.Validate()
       at NHibernate.Cfg.Configuration.BuildSessionFactory()
       at ProcessSystem.Init.DependencyResolverInitializer.<Initialize>b__1()
       at StructureMap.Pipeline.LambdaInstance`1.<>c__DisplayClass8.<.ctor>b__6(IContext s)
       at StructureMap.Pipeline.LambdaInstance`1.build(Type pluginType, BuildSession session)
  InnerException:

Any help would be greatly appreciated.

Thanks,
Patrick

Roger Kratz

unread,
Mar 21, 2012, 2:50:42 PM3/21/12
to nhu...@googlegroups.com
Custom user types is suppose to work just fine with Envers. Can you send a failing test (using hbm mapping) here please?
https://nhibernate.jira.com/browse/NHE


________________________________
Från: nhu...@googlegroups.com [nhu...@googlegroups.com] för Patrick [rpmc...@gmail.com]
Skickat: den 21 mars 2012 19:28
Till: nhu...@googlegroups.com
Ämne: [nhusers] Envers with a PrimitiveType

Thanks,
Patrick

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/Pw0Nkff7kL0J.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

Patrick

unread,
Mar 21, 2012, 8:03:38 PM3/21/12
to nhu...@googlegroups.com
Having never used nHibernate before it will probably take me a while to get a test added to the Envers source code, but I'm willing to give it a shot.  I'll start working on it tonight.  Would you be willing to accept a small custom test project?

Anyway, Envers very well may support it and I'm just doing something wrong.  If anybody has an idea of what I might be screwing up (or where to start looking), I'd appreciate it.

-Patrick



On Wednesday, March 21, 2012 1:50:42 PM UTC-5, Roger wrote:
Custom user types is suppose to work just fine with Envers. Can you send a failing test (using hbm mapping) here please?
https://nhibernate.jira.com/browse/NHE


________________________________
Från: nhu...@googlegroups.com [nhu...@googlegroups.com] för Patrick

To unsubscribe from this group, send email to nhusers+unsubscribe@googlegroups.com.

Roger Kratz

unread,
Mar 22, 2012, 4:51:55 AM3/22/12
to nhu...@googlegroups.com

<< Would you be willing to accept a small custom test project?>>

 

I really would prefer an unit test. A good starting point is to copy/paste a custom user type test already in envers code base – they are here

https://bitbucket.org/RogerKratz/nhibernate.envers/src/d9c03ac1dbd0/Src/NHibernate.Envers.Tests/Integration/CustomType

Simply add a new test in that folder and create a patch (or do a pull request on bitbucket).

 

Thanks

Roger

To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

--

You received this message because you are subscribed to the Google Groups "nhusers" group.

To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/ASKN74a-YSYJ.


To post to this group, send email to nhu...@googlegroups.com

.
To unsubscribe from this group, send email to
nhusers+u...@googlegroups.com.


For more options, visit this group at

Patrick

unread,
Mar 22, 2012, 9:26:18 AM3/22/12
to nhu...@googlegroups.com
Will do.  I started working on it last night.  Hopefully I'll have something worked out by this weekend.

On a related note, I also have an ICompositeUserType that wasn't working but I think I know why.  I'm treating it as a collection of value types (no Id) which I think is what section 9.1 of the documentation says is not supported.  Am I understanding that correctly?

Thanks,
Patrick

To unsubscribe from this group, send email to nhusers+unsubscribe@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/ASKN74a-YSYJ.
To post to this group, send email to nhu...@googlegroups.com

.
To unsubscribe from this group, send email to
nhusers+unsubscribe@googlegroups.com.


For more options, visit this group at

Roger Kratz

unread,
Mar 22, 2012, 9:52:23 AM3/22/12
to nhu...@googlegroups.com

<< I'm treating it as a collection of value types (no Id) which I think is what section 9.1 of the documentation says is not supported.  Am I understanding that correctly? >>

 

Yes, it’s not currently supported I’m afraid.

 

To be honest, don’t really know what happens in your scenario (a collection of custom user types). Out of curiousity – don’t you get a “nice” (hmm.. well…) exception saying this isn’t supported? What is your stack trace?

 

/Roger

 

From: nhu...@googlegroups.com [mailto:nhu...@googlegroups.com] On Behalf Of Patrick
Sent: den 22 mars 2012 14:26
To: nhu...@googlegroups.com
Subject: Re: [nhusers] Envers with a PrimitiveType

 

Will do.  I started working on it last night.  Hopefully I'll have something worked out by this weekend.



On a related note, I also have an ICompositeUserType that wasn't working but I think I know why.  I'm treating it as a collection of value types (no Id) which I think is what section 9.1 of the documentation says is not supported.  Am I understanding that correctly?

Thanks,
Patrick

On Thursday, March 22, 2012 3:51:55 AM UTC-5, Roger wrote:

<< Would you be willing to accept a small custom test project?>>

 

I really would prefer an unit test. A good starting point is to copy/paste a custom user type test already in envers code base – they are here

https://bitbucket.org/RogerKratz/nhibernate.envers/src/d9c03ac1dbd0/Src/NHibernate.Envers.Tests/Integration/CustomType

Simply add a new test in that folder and create a patch (or do a pull request on bitbucket).

 

Thanks

Roger

 

To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.


For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/ASKN74a-YSYJ.
To post to this group, send email to nhu...@googlegroups.com

.
To unsubscribe from this group, send email to
nhusers+u...@googlegroups.com.


For more options, visit this group at

--
You received this message because you are subscribed to the Google Groups "nhusers" group.

To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/Mi76anx1rtoJ.


To post to this group, send email to nhu...@googlegroups.com.

To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

Patrick

unread,
Mar 25, 2012, 10:49:44 AM3/25/12
to nhu...@googlegroups.com
Yeah, the message was decent.  Says it wasn't supported but not really why (the "component[StartDateTime,EndDateTime]" threw me a little).  It was easy enough to find in the documentation though.  Here is the stack trace:


NHibernate.MappingException was unhandled by user code
  Message=Type not supported for auditing: component[StartDateTime,EndDateTime], on entity ProcessSystem.Domain.Training.Class, property 'TimePeriods'.
  Source=NHibernate.Envers
  StackTrace:
       at NHibernate.Envers.Configuration.Metadata.AuditMetadataGenerator.ThrowUnsupportedTypeException(IType type, String entityName, String propertyName) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\Metadata\AuditMetadataGenerator.cs:line 522
       at NHibernate.Envers.Configuration.Metadata.CollectionMetadataGenerator.addValueToMiddleTable(IValue value, XmlElement xmlMapping, QueryGeneratorBuilder queryGeneratorBuilder, String prefix, String[] joinColumns) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\Metadata\CollectionMetadataGenerator.cs:line 446
       at NHibernate.Envers.Configuration.Metadata.CollectionMetadataGenerator.AddWithMiddleTable() in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\Metadata\CollectionMetadataGenerator.cs:line 315
       at NHibernate.Envers.Configuration.Metadata.CollectionMetadataGenerator.AddCollection() in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\Metadata\CollectionMetadataGenerator.cs:line 93
       at NHibernate.Envers.Configuration.Metadata.AuditMetadataGenerator.addValueInSecondPass(XmlElement parent, IValue value, ICompositeMapperBuilder currentMapper, String entityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, Boolean insertable, Boolean processModifiedFlag) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\Metadata\AuditMetadataGenerator.cs:line 183
       at NHibernate.Envers.Configuration.Metadata.AuditMetadataGenerator.AddValue(XmlElement parent, IValue value, ICompositeMapperBuilder currentMapper, String entityName, EntityXmlMappingData xmlMappingData, PropertyAuditingData propertyAuditingData, Boolean insertable, Boolean firstPass, Boolean processModifiedFlag) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\Metadata\AuditMetadataGenerator.cs:line 210
       at NHibernate.Envers.Configuration.Metadata.AuditMetadataGenerator.AddProperties(XmlElement parent, IEnumerable`1 properties, ICompositeMapperBuilder currentMapper, ClassAuditingData auditingData, String entityName, EntityXmlMappingData xmlMappingData, Boolean firstPass) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\Metadata\AuditMetadataGenerator.cs:line 224
       at NHibernate.Envers.Configuration.Metadata.AuditMetadataGenerator.GenerateSecondPass(PersistentClass pc, ClassAuditingData auditingData, EntityXmlMappingData xmlMappingData) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\Metadata\AuditMetadataGenerator.cs:line 508
       at NHibernate.Envers.Configuration.EntitiesConfigurator.Configure(Configuration cfg, IMetaDataStore metaDataStore, GlobalConfiguration globalCfg, AuditEntitiesConfiguration verEntCfg, IAuditStrategy auditStrategy, XmlDocument revisionInfoXmlMapping, XmlElement revisionInfoRelationMapping) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\EntitiesConfigurator.cs:line 79
       at NHibernate.Envers.Configuration.AuditConfiguration..ctor(Configuration cfg, IMetaDataProvider metaDataProvider) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\AuditConfiguration.cs:line 36
       at NHibernate.Envers.Configuration.AuditConfiguration.GetFor(Configuration cfg) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\AuditConfiguration.cs:line 81
       at NHibernate.Cfg.NhConfigurationExtension.IntegrateWithEnvers(Configuration configuration, AuditEventListener auditEventListener, IMetaDataProvider metaDataProvider) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\NhConfigurationExtension.cs:line 27
       at NHibernate.Cfg.NhConfigurationExtension.IntegrateWithEnvers(Configuration configuration, IMetaDataProvider metaDataProvider) in d:\develop\NHibernate.Envers\Src\NHibernate.Envers\Configuration\NhConfigurationExtension.cs:line 46
       at ProcessSystem.NHibernateProvider.NHibernateInitializer.Initialize() in C:\Users\Patrick\Dev\ProcessSystem\app\ProcessSystem.NHibernateProvider\NHibernateInitializer.cs:line 43
       at ProcessSystem.Init.DependencyResolverInitializer.<Initialize>b__1() in C:\Users\Patrick\Dev\ProcessSystem\app\ProcessSystem.Init\DependencyResolverInitializer.cs:line 18

       at StructureMap.Pipeline.LambdaInstance`1.<>c__DisplayClass8.<.ctor>b__6(IContext s)
       at StructureMap.Pipeline.LambdaInstance`1.build(Type pluginType, BuildSession session)
  InnerException:

For reference, here is the type:

using System;
using SharpLite.Domain;
using System.ComponentModel.DataAnnotations;

namespace ProcessSystem.Domain
{
    public class TimePeriod
    {
        protected TimePeriod() { }

        public TimePeriod(DateTime startTime, DateTime endTime)
        {
            StartDateTime = startTime;
            EndDateTime = endTime;
        }

        public virtual DateTime StartDateTime { get; protected set; }

        public virtual DateTime EndDateTime { get; protected set; }

        [Required(ErrorMessage = "Date must be provided")]
        public virtual DateTime Date
        {
            get    { return StartDateTime.Date; }
        }

        [Display(Name="Start Time")]
        [Required(ErrorMessage = "StartTime must be provided")]
        public virtual TimeSpan StartTime
        {
            get    { return StartDateTime.TimeOfDay; }
        }

        [Required(ErrorMessage = "EndTime must be provided")]
        public virtual TimeSpan EndTime
        {
            get    { return EndDateTime.TimeOfDay;    }
        }

        public override bool Equals(object obj)
        {...}

        public override int GetHashCode()
        {...}
    }
}

Basically, mapped to two DateTime fields in the DB and treated as a collection of values:

    public class Class : Entity, ITrainingFulfillment
    {
        public Class()
        {
            TimePeriods = new List<TimePeriod>();
        }

        // Lots of other stuff

        public virtual IList<TimePeriod> TimePeriods { get; protected set; }
    }

I can provide more information if it would be helpful or try to make a test case for that as well if you would like.  I'm hoping I'll actually get some time today to work on it.

-Patrick

To unsubscribe from this group, send email to nhusers+unsubscribe@​googlegroups.com.


For more options, visit this group at http://groups.google.com/​group/nhusers?hl=en.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/​msg/nhusers/-/ASKN74a-YSYJ.
To post to this group, send email to nhu...@googlegroups.com

.
To unsubscribe from this group, send email to
nhusers+unsubscribe@​googlegroups.com.


For more options, visit this group at

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/​msg/nhusers/-/Mi76anx1rtoJ.
To post to this group, send email to nhu...@googlegroups.com.

To unsubscribe from this group, send email to nhusers+unsubscribe@​googlegroups.com.

Patrick

unread,
Mar 25, 2012, 12:42:50 PM3/25/12
to nhu...@googlegroups.com
Okay, I've created a test case with a very basic PrimitiveType that maps an int in the DB to a class with a char value.  It appears to be failing correctly but please let me know if I messed it up (never used nUnit before either).

https://nhibernate.jira.com/browse/NHE-66

-Patrick

On Thursday, March 22, 2012 3:51:55 AM UTC-5, Roger wrote:

To unsubscribe from this group, send email to nhusers+unsubscribe@​googlegroups.com.


For more options, visit this group at http://groups.google.com/​group/nhusers?hl=en.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/​msg/nhusers/-/ASKN74a-YSYJ.
To post to this group, send email to nhu...@googlegroups.com

.
To unsubscribe from this group, send email to
nhusers+unsubscribe@​googlegroups.com.


For more options, visit this group at

Patrick

unread,
Mar 30, 2012, 11:07:46 AM3/30/12
to nhu...@googlegroups.com
Thanks for helping me resolve that issue, but I'm having a separate problem now (maybe I need a new thread).  I've tried replacing the DefaultRevisionEntity with one of my own making but in the schema nHibernate is generating (and expecting) both the entities fields (Id & RevisionDate) and the defaults (REV & REVTSTMP).  Any thoughts?  Relevant code and schema are below.

    [RevisionEntity(typeof(EnversRevisionListener))]
    public class EnversRevisionEntity : DefaultRevisionEntity
    {
        public EnversRevisionEntity() { }

        public virtual User User { get; set; }
    }

    create table Audit.REVINFO (
        Id INT not null,
       UserFk INT null,
       RevisionDate DATETIME null,
       REV INT IDENTITY NOT NULL,
       REVTSTMP DateTime null,
       primary key (REV)
    )

Thanks,
Patrick

Roger Kratz

unread,
Mar 30, 2012, 6:11:43 PM3/30/12
to nhu...@googlegroups.com
I'm not really sure I understand your problem but...

It's mandatory that the revision entity has a revision number and a revision timestamp. However, you can rename it to whatever you want though (both in domain model and in db schema).

It seems you're using attribute configuration? In that case, something like...

[RevisionEntity(typeof(EnversRevisionListener))]
public class EnversRevisionEntity
{
[RevisionNumber]
public virtual long RevisionId {get;set;}
[RevisionTimestamp]
public virtual DateTime TheTimeStamp {get;set;}
}


Or if you're using fluent cfg...

public class EnversRevisionEntity
{
public virtual long RevisionId {get;set;}
public virtual DateTime TheTimeStamp {get;set;}
}
fluentCfg.SetRevisionEntity<EnversRevisionEntity>(e => e.RevisionId, e => e.TheTimeStamp, new EnversRevisionListener());


/Roger

________________________________
Från: nhu...@googlegroups.com [nhu...@googlegroups.com] för Patrick [rpmc...@gmail.com]
Skickat: den 30 mars 2012 17:07
Till: nhu...@googlegroups.com
Ämne: Re: [nhusers] Envers with a PrimitiveType

Thanks for helping me resolve that issue, but I'm having a separate problem now (maybe I need a new thread). I've tried replacing the DefaultRevisionEntity with one of my own making but in the schema nHibernate is generating (and expecting) both the entities fields (Id & RevisionDate) and the defaults (REV & REVTSTMP). Any thoughts? Relevant code and schema are below.

[RevisionEntity(typeof(EnversRevisionListener))]
public class EnversRevisionEntity : DefaultRevisionEntity
{
public EnversRevisionEntity() { }

public virtual User User { get; set; }
}

create table Audit.REVINFO (
Id INT not null,
UserFk INT null,
RevisionDate DATETIME null,
REV INT IDENTITY NOT NULL,
REVTSTMP DateTime null,
primary key (REV)
)

Thanks,
Patrick

On Sunday, March 25, 2012 11:42:50 AM UTC-5, Patrick wrote:
Okay, I've created a test case with a very basic PrimitiveType that maps an int in the DB to a class with a char value. It appears to be failing correctly but please let me know if I messed it up (never used nUnit before either).

https://nhibernate.jira.com/browse/NHE-66

-Patrick

On Thursday, March 22, 2012 3:51:55 AM UTC-5, Roger wrote:
<< Would you be willing to accept a small custom test project?>>

I really would prefer an unit test. A good starting point is to copy/paste a custom user type test already in envers code base – they are here
https://bitbucket.org/​RogerKratz/nhibernate.envers/​src/d9c03ac1dbd0/Src/​NHibernate.Envers.Tests/​Integration/CustomType<https://bitbucket.org/RogerKratz/nhibernate.envers/src/d9c03ac1dbd0/Src/NHibernate.Envers.Tests/Integration/CustomType>
Simply add a new test in that folder and create a patch (or do a pull request on bitbucket).

Thanks
Roger

From: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com> [mailto:nhusers@googlegroups.​com<mailto:nhu...@googlegroups.com>] On Behalf Of Patrick
Sent: den 22 mars 2012 01:04
To: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>
Subject: Re: [nhusers] Envers with a PrimitiveType

Having never used nHibernate before it will probably take me a while to get a test added to the Envers source code, but I'm willing to give it a shot. I'll start working on it tonight. Would you be willing to accept a small custom test project?

Anyway, Envers very well may support it and I'm just doing something wrong. If anybody has an idea of what I might be screwing up (or where to start looking), I'd appreciate it.

-Patrick


On Wednesday, March 21, 2012 1:50:42 PM UTC-5, Roger wrote:
Custom user types is suppose to work just fine with Envers. Can you send a failing test (using hbm mapping) here please?
https://nhibernate.jira.com/​browse/NHE<https://nhibernate.jira.com/browse/NHE>

______________________________​__
Från: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com> [nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>] för Patrick
Skickat: den 21 mars 2012 19:28
Till: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>
Ämne: [nhusers] Envers with a PrimitiveType

I'm trying to get Envers up and running in my project (based on S#arp Lite) and am having trouble getting it to work with a custom PrimitiveType. Basically, I using the Enumeration class from Jimmy Bogard's site:
http://lostechies.com/​jimmybogard/2008/08/12/​enumeration-classes/<http://lostechies.com/jimmybogard/2008/08/12/enumeration-classes/>

and tying it into nHibernate with an EnumerationType<T> that inherits from PrimitiveType. That code is mostly stolen from:
http://code.google.com/p/​codecampserver/source/browse/​trunk/src/Infrastructure.​NHibernate/DataAccess/​EnumerationType.cs?r=1063<http://code.google.com/p/codecampserver/source/browse/trunk/src/Infrastructure.NHibernate/DataAccess/EnumerationType.cs?r=1063>
To view this discussion on the web visit https://groups.google.com/d/​msg/nhusers/-/Pw0Nkff7kL0J<https://groups.google.com/d/msg/nhusers/-/Pw0Nkff7kL0J>.
To post to this group, send email to nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>.
To unsubscribe from this group, send email to nhusers+unsubscribe@​googlegroups.com<mailto:nhusers%2Bunsu...@googlegroups.com>.
For more options, visit this group at http://groups.google.com/​group/nhusers?hl=en<http://groups.google.com/group/nhusers?hl=en>.
--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/​msg/nhusers/-/ASKN74a-YSYJ<https://groups.google.com/d/msg/nhusers/-/ASKN74a-YSYJ>.
To post to this group, send email to nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>.
To unsubscribe from this group, send email to nhusers+unsubscribe@​googlegroups.com<mailto:nhusers+u...@googlegroups.com>.
For more options, visit this group at http://groups.google.com/​group/nhusers?hl=en<http://groups.google.com/group/nhusers?hl=en>.

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/MaVN8-GvpTwJ.
To post to this group, send email to nhu...@googlegroups.com.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

Patrick

unread,
Mar 30, 2012, 7:42:19 PM3/30/12
to nhu...@googlegroups.com
I'll try and explain it a little better.  At the end of section 4 of the documentation, there is this sentence: "Having an "empty" revision entity - that is, with no additional properties except the two mandatory ones - is
also an easy way to change the names of the table and of the properties in the revisions table automatically generated by Envers."  To me, that says the default fields would be renamed, not just added to.  This is the default schema for the REVINFO table without a custom entity:

    create table Audit.REVINFO (

       REV INT IDENTITY NOT NULL,
       REVTSTMP DateTime null,
       primary key (REV)
    )

If I use the EnversRevisionEntity I posted earlier (which inherits from DefaultEnversEntity which already has the annotations you described), I would expect this schema:

    create table Audit.REVINFO (
        Id INT IDENTITY not null,

       UserFk INT null,
       RevisionDate DATETIME null,
       primary key (Id)
    )

but instead I get:

    create table Audit.REVINFO (
        Id INT not null,                         -- why isn't this the IDENTITY

       UserFk INT null,
       RevisionDate DATETIME null,
       REV INT IDENTITY NOT NULL, -- why is this still here
       REVTSTMP DateTime null,        -- and this one
       primary key (REV)                     -- and why isn't this Id
    )

I figure either the documentation is a little misleading or I'm doing something wrong.

-Patrick


On Friday, March 30, 2012 5:11:43 PM UTC-5, Roger wrote:
I'm not really sure I understand your problem but...

It's mandatory that the revision entity has a revision number and a revision timestamp. However, you can rename it to whatever you want though (both in domain model and in db schema).

It seems you're using attribute configuration? In that case, something like...

[RevisionEntity(typeof(EnversRevisionListener))]
public class EnversRevisionEntity
{
     [RevisionNumber]
     public virtual long RevisionId {get;set;}
     [RevisionTimestamp]
     public virtual DateTime TheTimeStamp {get;set;}
}


Or if you're using fluent cfg...

public class EnversRevisionEntity
{
public virtual long RevisionId {get;set;}
public virtual DateTime TheTimeStamp {get;set;}
}
fluentCfg.SetRevisionEntity<EnversRevisionEntity>(e => e.RevisionId, e => e.TheTimeStamp, new EnversRevisionListener());


/Roger

________________________________
Från: nhu...@googlegroups.com [nhu...@googlegroups.com] för Patrick

Peter Morris

unread,
Mar 31, 2012, 5:33:06 AM3/31/12
to nhusers
>It's mandatory that the revision entity has a revision number and a revision timestamp. However, you can rename it to whatever you want though (both in domain model and in db schema).

Would it be possible to enable us to specify that this could be any
unique key, such as Guid.Comb?
Also, are you using UTC times for the timestamps?

Roger Kratz

unread,
Apr 1, 2012, 10:49:52 AM4/1/12
to nhu...@googlegroups.com
<<Would it be possible to enable us to specify that this could be any
unique key, such as Guid.Comb?>>

No, not currently. It must be some sort of number because it's used in some queries (eg "<=", "max", "between").

<<Also, are you using UTC times for the timestamps?>>

Hmm... It _should_ be, but I'm not sure it is. If it isn't, please JIRA this.

________________________________________
Från: nhu...@googlegroups.com [nhu...@googlegroups.com] f&#246;r Peter Morris [mrpm...@gmail.com]
Skickat: den 31 mars 2012 11:33
Till: nhusers
Ämne: [nhusers] Re: Envers with a PrimitiveType

--


You received this message because you are subscribed to the Google Groups "nhusers" group.

Roger Kratz

unread,
Apr 1, 2012, 10:53:44 AM4/1/12
to nhu...@googlegroups.com
What's you mapping for EnversRevisionEntity?

________________________________
Från: nhu...@googlegroups.com [nhu...@googlegroups.com] för Patrick [rpmc...@gmail.com]
Skickat: den 31 mars 2012 01:42


Till: nhu...@googlegroups.com
Ämne: Re: [nhusers] Envers with a PrimitiveType

I'll try and explain it a little better. At the end of section 4 of the documentation, there is this sentence: "Having an "empty" revision entity - that is, with no additional properties except the two mandatory ones - is

but instead I get:

-Patrick


/Roger

________________________________
Från: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com> [nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>] för Patrick


Skickat: den 30 mars 2012 17:07

Till: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>


Ämne: Re: [nhusers] Envers with a PrimitiveType

Thanks for helping me resolve that issue, but I'm having a separate problem now (maybe I need a new thread). I've tried replacing the DefaultRevisionEntity with one of my own making but in the schema nHibernate is generating (and expecting) both the entities fields (Id & RevisionDate) and the defaults (REV & REVTSTMP). Any thoughts? Relevant code and schema are below.

[RevisionEntity(typeof(EnversRevisionListener))]
public class EnversRevisionEntity : DefaultRevisionEntity
{
public EnversRevisionEntity() { }

public virtual User User { get; set; }
}

create table Audit.REVINFO (
Id INT not null,
UserFk INT null,
RevisionDate DATETIME null,
REV INT IDENTITY NOT NULL,
REVTSTMP DateTime null,
primary key (REV)
)

Thanks,
Patrick


--
You received this message because you are subscribed to the Google Groups "nhusers" group.

To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/olwpYMmefLkJ.

Patrick

unread,
Apr 3, 2012, 6:43:20 PM4/3/12
to nhu...@googlegroups.com
Well, I'm using the ConventionModelMapper so no real configuration to speak of.  I can still post it if you would like, but I was hoping I had just made some common mistake.

I'm under a pretty tight deadline so I just added the required properties directly to my revision class and removed the inheritance from DefaultRevisionEntity.  The schema is now what I expected.  I really think it might be my fault so I'll see if I can reproduce the issue with a minimal project.  If so, I'll see if I can find a good spot for another test case.

-Patrick


On Sunday, April 1, 2012 9:53:44 AM UTC-5, Roger wrote:
What's you mapping for EnversRevisionEntity?

________________________________
Från: nhu...@googlegroups.com [nhu...@googlegroups.com] för Patrick

________________________________
Från: nhu...@googlegroups.com<mailto:nhusers@googlegroups.com> [nhu...@googlegroups.com<mailto:nhusers@googlegroups.com>] för Patrick


Skickat: den 30 mars 2012 17:07


Ämne: Re: [nhusers] Envers with a PrimitiveType

Thanks for helping me resolve that issue, but I'm having a separate problem now (maybe I need a new thread).  I've tried replacing the DefaultRevisionEntity with one of my own making but in the schema nHibernate is generating (and expecting) both the entities fields (Id & RevisionDate) and the defaults (REV & REVTSTMP).  Any thoughts?  Relevant code and schema are below.

    [RevisionEntity(typeof(EnversRevisionListener))]
    public class EnversRevisionEntity : DefaultRevisionEntity
    {
        public EnversRevisionEntity() { }

        public virtual User User { get; set; }
    }

    create table Audit.REVINFO (
        Id INT not null,
       UserFk INT null,
       RevisionDate DATETIME null,
       REV INT IDENTITY NOT NULL,
       REVTSTMP DateTime null,
       primary key (REV)
    )

Thanks,
Patrick


--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/olwpYMmefLkJ.
To post to this group, send email to nhu...@googlegroups.com.

To unsubscribe from this group, send email to nhusers+unsubscribe@googlegroups.com.

Roger Kratz

unread,
Apr 3, 2012, 8:02:31 PM4/3/12
to nhu...@googlegroups.com
When having a custom revision entity, the schema generated is outside the control of envers so to speak. Simple NH Core mapping. So something seems strange here...

<<If so, I'll see if I can find a good spot for another test case.>>

Please do.

Thanks.
Roger

________________________________
Från: nhu...@googlegroups.com [nhu...@googlegroups.com] för Patrick [rpmc...@gmail.com]
Skickat: den 4 april 2012 00:43


Till: nhu...@googlegroups.com
Ämne: Re: [nhusers] Envers with a PrimitiveType

Well, I'm using the ConventionModelMapper so no real configuration to speak of. I can still post it if you would like, but I was hoping I had just made some common mistake.

I'm under a pretty tight deadline so I just added the required properties directly to my revision class and removed the inheritance from DefaultRevisionEntity. The schema is now what I expected. I really think it might be my fault so I'll see if I can reproduce the issue with a minimal project. If so, I'll see if I can find a good spot for another test case.

-Patrick


On Sunday, April 1, 2012 9:53:44 AM UTC-5, Roger wrote:
What's you mapping for EnversRevisionEntity?

________________________________
Från: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com> [nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>] för Patrick


Skickat: den 31 mars 2012 01:42

Till: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>

but instead I get:

-Patrick

/Roger

________________________________
Från: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com><mailto:nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>> [nhu...@googlegroups.com<mailto:nhu...@googlegroups.com><mailto:nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>>] för Patrick


Skickat: den 30 mars 2012 17:07

Till: nhu...@googlegroups.com<mailto:nhu...@googlegroups.com><mailto:nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>>


Ämne: Re: [nhusers] Envers with a PrimitiveType

Thanks for helping me resolve that issue, but I'm having a separate problem now (maybe I need a new thread). I've tried replacing the DefaultRevisionEntity with one of my own making but in the schema nHibernate is generating (and expecting) both the entities fields (Id & RevisionDate) and the defaults (REV & REVTSTMP). Any thoughts? Relevant code and schema are below.

[RevisionEntity(typeof(EnversRevisionListener))]
public class EnversRevisionEntity : DefaultRevisionEntity
{
public EnversRevisionEntity() { }

public virtual User User { get; set; }
}

create table Audit.REVINFO (
Id INT not null,
UserFk INT null,
RevisionDate DATETIME null,
REV INT IDENTITY NOT NULL,
REVTSTMP DateTime null,
primary key (REV)
)

Thanks,
Patrick

--
You received this message because you are subscribed to the Google Groups "nhusers" group.
To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/olwpYMmefLkJ.

To post to this group, send email to nhu...@googlegroups.com<mailto:nhu...@googlegroups.com>.
To unsubscribe from this group, send email to nhusers+u...@googlegroups.com<mailto:nhusers%2Bunsu...@googlegroups.com>.


For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.

--


You received this message because you are subscribed to the Google Groups "nhusers" group.

To view this discussion on the web visit https://groups.google.com/d/msg/nhusers/-/GfRqY11ujWYJ.


To post to this group, send email to nhu...@googlegroups.com.

To unsubscribe from this group, send email to nhusers+u...@googlegroups.com.

Peter Morris

unread,
Apr 4, 2012, 3:43:31 AM4/4/12
to nhusers
> <<Would it be possible to enable us to specify that this could be any
> unique key, such as Guid.Comb?>>
>
> No, not currently. It must be some sort of number because it's used in some queries (eg "<=", "max", "between").

Couldn't the datetime be used for that? Surely people think in terms
of Revisions and revision ranges, not revision numbers?


> <<Also, are you using UTC times for the timestamps?>>
>
> Hmm... It _should_ be, but I'm not sure it is. If it isn't, please JIRA this.

No, it only uses DateTime.Now - Where do I go to add it to JIRA?

Roger Kratz

unread,
Apr 4, 2012, 3:58:14 AM4/4/12
to nhu...@googlegroups.com
<< Couldn't the datetime be used for that? >>

Depending on the precision on the db column you might end up with two identical datetimes.

<< Surely people think in terms of Revisions and revision ranges, not revision numbers?>>

Yes, the revision id has no real business value. It's a primary key.

<< No, it only uses DateTime.Now - Where do I go to add it to JIRA?>>

https://nhibernate.jira.com/browse/NHE

--

Reply all
Reply to author
Forward
0 new messages