-->
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.  [ 56 posts ]  Go to page Previous  1, 2, 3, 4  Next
Author Message
 Post subject:
PostPosted: Wed Jun 21, 2006 3:39 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
I love this version! The support for generics and nullables are clean and intuitive.

I've hit one wall so far that I haven't been quite able to figure out. Using either the NHibernate.dll from the bin directory in the download or a recompiled version (upgraded to log4net 1.2.10), I receive an error on either a version or timestamp mapping:

The element 'class' in namespace 'urn:nhibernate-mapping-2.0' has invalid child element 'version'

My mapping is:

Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" default-lazy="false">
   <class name="MobysThinkTank.mobyProject.User, mobyProject" table="[User]">
      <id name="Id" type="Int32" unsaved-value="0" access="nosetter.camelcase">
         <column name="userId" not-null="true" unique="true" />
         <generator class="native" />
      </id>

      <property name="Username" column="Username"/>
      <property name="Password" column="Password"/>
      <property name="LastLoginDate" column="LastLoginDate"/>
      <!--<timestamp name="LastUpdateDate" column="LastUpdateDate" /> -->
      <version name="Version" />
   </class>
</hibernate-mapping>


I've looked at the online docs and the xsd and don't see anything that should be amiss. I'm guessing I missed something very simple, though.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 3:49 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
Figured it out.... version is declared in a sequence in the xsd above the properties and I had it declared below. Flipping that order cured it all.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 3:53 pm 
Newbie

Joined: Wed Jun 21, 2006 2:45 pm
Posts: 16
First off - fantastic work.

I'm so glad to see the generics in here.

I'm new to Hibernate, and I was using the quickstart.

A couple of questions.

1. I saw above on how to load a single entity, ie:
User justAddedUser = session.Load<User>(newUser.Id);

2. What is the correct format to load all users?

I tried this:

List<User> users = session.CreateCriteria(typeof(User)).List<User>();

but it was wanting a List instead of an List<User> from the CreateCriteria

I ended up using:
List<User> users = (List<User>)session.CreateCriteria(typeof(User)).List<User>();

This worked, but it seems to be a bit verbose - is there a better way to handle this?

Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 4:22 pm 
Regular
Regular

Joined: Wed Jun 21, 2006 3:13 pm
Posts: 110
SteveG wrote:
First off - fantastic work.

1. I saw above on how to load a single entity, ie:
User justAddedUser = session.Load<User>(newUser.Id);

2. What is the correct format to load all users?

I tried this:

List<User> users = session.CreateCriteria(typeof(User)).List<User>();

but it was wanting a List instead of an List<User> from the CreateCriteria

I ended up using:
List<User> users = (List<User>)session.CreateCriteria(typeof(User)).List<User>();

This worked, but it seems to be a bit verbose - is there a better way to handle this?

Thanks!


Steve... Good thing we're working on similar domain objects ;-) Here's my code:

public static User Get(int id)
{
return DbSessionContext.Current.Session.Load<User>(id);
}

public static IList<User> List()
{
return DbSessionContext.Current.Session.CreateCriteria(typeof(User)).List<User>();
}

The issue with your first attempt is that it wants to return an IList and not a List. I guess, depending on the problem at hand, returning an IList is generally going to be an acceptable approach... .saves you from explicit casting too.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jun 21, 2006 4:45 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
It seems like there should be a new ISession.CreateCriteria<T>() method added. i.e. so that you can do something like,

Code:
s.CreateCriteria<User>();

instead of,

Code:
s.CreateCriteria(typeof(User));

Not a big deal, just a little less verbose from an end user's perspective. I'm not sure though, would that be considered proper usage of generics?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jun 26, 2006 9:52 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
jemiller wrote:
It seems like there should be a new ISession.CreateCriteria<T>() method added. i.e. so that you can do something like,

Code:
s.CreateCriteria<User>();

instead of,

Code:
s.CreateCriteria(typeof(User));

Not a big deal, just a little less verbose from an end user's perspective. I'm not sure though, would that be considered proper usage of generics?


In the future, projections will be added to criteria API and then your proposed solution will break, that's why I decided against it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 27, 2006 10:19 am 
Beginner
Beginner

Joined: Wed Apr 19, 2006 9:16 am
Posts: 24
Just noticed and downloaded the new alpha today, excellent work, thanks!

Browsing through the code for the various generic additions, I noticed the generic overloads for Get, Load and such like don't have the "new()" generic constraint. Is this per design? It would be nice to be informed of failure to implement a default constructor at compile time.

regards,
Willem van Rumpt


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jul 17, 2006 10:35 am 
Beginner
Beginner

Joined: Tue Jan 17, 2006 12:55 pm
Posts: 49
Is there any indication of a release date for the final version? Just a ball park figure would be useful.

Ta


Top
 Profile  
 
 Post subject: NHibernate 1.2.0.Alpha
PostPosted: Fri Jul 28, 2006 10:16 am 
Newbie

Joined: Fri Jul 28, 2006 10:11 am
Posts: 7
Location: Nottinghamshire, England
I would like to second this request.

I have been looking at Nhibernate as a possible OR mapper for a new project that I am working on and now that the Alpha is available for .net2 I would like to incorporate it into the project.

So... Understanding that the people behind this wonderfull project are busy with other things too... what is the ETA on a stable release?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 28, 2006 4:06 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Unfortunately I can't tell you any date. Please see my recent post for more details.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 29, 2006 4:31 pm 
Newbie

Joined: Fri Jul 28, 2006 10:11 am
Posts: 7
Location: Nottinghamshire, England
Hi,

Thanks for the quick reply :)

I really admire the work that has been put into this project... as you have predominantly taking a TDD approach to the project. I think that I will feel safe with using the Alpha version (probably collect the latest version from SVN when ready -- just to be sure) in the final release.
Hell -- I can always give the client a patch update when release date arrives for Nhibernate 1.2 (I will probably have to release a few to fix my own code anyhow :P

Again... thanks and keep up the good work -- now were is that donate button :D


Top
 Profile  
 
 Post subject: IList<T> and Bag
PostPosted: Tue Aug 01, 2006 9:52 pm 
Newbie

Joined: Tue Aug 01, 2006 9:42 pm
Posts: 6
NHibernate supports using IList and <Bag> together for unordered collection semantics. I tried the generic version of this in 1.2.0 alpha and recieved an error when I used IList<T> and <Bag> together. Is this intentional? If so, why isn't the generic analog of the IList <Bag> affinity supported?

The error that I get is as follows:

Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericBag`1[CalendarManagement.RecurrenceException]' to type 'System.Collections.Generic.List`1[CalendarManagement.RecurrenceException]'.

I am using an underlying collection of List<RecurrenceException> exposed through property accessors as IList<RecurrenceException>


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 02, 2006 5:06 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
It should work, please describe your problem with all details (mappings, code, stack trace) in a separate post. The message indicates to me that you have property exposed as List<RecurrenceException> but you explicitly say you use IList<RecurrenceException> so I can't tell what the problem is.


Top
 Profile  
 
 Post subject: Re: IList<T> and Bag
PostPosted: Wed Aug 02, 2006 7:41 am 
Expert
Expert

Joined: Thu Jan 19, 2006 4:29 pm
Posts: 348
Aaron_Murrell wrote:
Unable to cast object of type 'NHibernate.Collection.Generic.PersistentGenericBag`1[CalendarManagement.RecurrenceException]' to type 'System.Collections.Generic.List`1[CalendarManagement.RecurrenceException]'.


Seems that somewhere You use List<RecurrenceException> instead of IList<RecurrenceException>. Try to change it...

EDIT: Note that in property setter, You can not cast "value" to List<RecurrenceException>, as it is not List<>. Not can this cast be done anywhere else (So the field must be IList<>, not List<>)

Gert

_________________
If a reply helps You, rate it!


Top
 Profile  
 
 Post subject: You got it
PostPosted: Fri Aug 04, 2006 2:14 pm 
Newbie

Joined: Tue Aug 01, 2006 9:42 pm
Posts: 6
Thanks!

You hit the nail right on the head. My field should have been of type IList<...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 56 posts ]  Go to page Previous  1, 2, 3, 4  Next

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.