I have map the entities in .hmb.xml and define attribute for all entity in classes.I have some basic accomplishment and get all the record using below code.
public List<DevelopmentStep> getDevelopmentSteps()
{
List<DevelopmentStep> developmentStep;[code]....
I have check from net that we can write HQL, Now the problem is how to execute this HQL like..
string hql = "From DevelopmentSteps d inner join table2 t2 d.id=t2.Id where d.id=IDValue";
What additional Classes or other thing I need to add to execute this kind of HQL?
Is there a way that I can call a function like (fadeIn or fadeOut) from the .cs?So thats my situation - I have a datalist of stuff. When A user clicks something on the list, it gives him some details about the thing he clicked and if he wants it, he clicks it again.now, on the first click I changed the OnClientClick of the button to fadeOut the datalist.so on the second click (after he confirms the item) it fades out.If he clicks one thing than click another thing, the fadeOut occurs.
I m adding some value to database and get the id of the inserted record then pass it to a popup using session.the problem is when i click on save button the popup is opened on client side before finishing the server side and like this the session is null. i tried to check if the session that i pass is null then thread.sleep(1000) but unformtunatly this is not working.after that the popup finsihs loading if i refresh the page i got the data as the session now have value.
I want to use NHibernate with Asp.net 3.5 but i don't know how to use it.I search on Google but couldn't find the complete explanation about why to use NHibernate,Advantages of using it and integration with Asp.net projects.
I am about to give up on this pos...unless somebody here simply gives me the right code to fix my problem. I'm tired of running in circles, and scouring the internet with no progress at all.
Problem: not updating collections with FK's.
Example:
Forum forum = new Forum("Sample"); category.AddForum(forum); categoryRepository.Update(category); <- fails with transient object error for forum with no CategoryId. Mapped right using References<Category> and HasMany<Forum>. Conventions are as follows.
Now, I've tried every possible setting for inverse, all the different cascades, on both sides. Nothing works. It just flat fails, telling me it can't insert NULL for Forum.CategoryId (field, not entity prop).
I've been reading up on DDD a little bit, and I am confused how this would fit in when using an ORM like NHibernate. Right now I have a .NET MVC application with fairly "fat" controllers, and I'm trying to figure out how best to fix that. Moving this business logic into the model layer would be the best way to do this, but I am unsure how one would do that.
My application is set up so that NHibernate's session is managed by an HttpModule (gets session / transaction out of my way), which is used by repositories that return the entity objects (Think S#arp arch... turns out a really duplicated a lot of their functionality in this). These repositories are used by DataServices, which right now are just wrappers around the Repositories (one-to-one mapping between them, e.g. UserDataService takes a UserRepository, or actually a Repository). These DataServices right now only ensure that data annotations decorating the entity classes are checked when saving / updating.
In this way, my entities are really just data objects, but do not contain any real logic. While I could put some things in the entity classes (e.g. an "Approve" method), when that action needs to do something like sending an e-mail, or touching other non-related objects, or, for instance, checking to see if there are any users that have the same e-mail before approving, etc., then the entity would need access to other repositories, etc. Injecting these with an IoC wouldn't work with NHibernate, so you'd have to use a factory pattern I'm assuming to get these. I don't see how you would mock those in tests though......................
I am working on NHibernate with oracle in ASP.Net. Now i am trying TDD(Test Driven Development). Can you tell me the best way to develop the TDD for NHibernate with oracle?I am using MbUnit with microdesk but it is not better approach for oracle but SQL server.
I have had no issues retrieving objects, but I've just got to a point with nested objects that I can't figure out.
I am using lazy=true and when accessing a lazy-load collection I get the message:
Initializing[type#3]-failed to lazily initialize a collection of role: [type], no session or session was closed
Even if I call SessionFactory.OpenSession() immediately prior to the object being accessed, it makes no difference. I have also tried accessing the collection in a using ISession block to no luck.
Edit to add - I do have current_session_context_class = web set in web.config, and I am using CurrentSessionContext.Bind on BeginRequest.
Not an MVC app
I read this - don't know how accurate it is, and it is Hibernate:
I am a newcomer to NHibernate and know a bit about WCF. I would like to know how they best play together.Should I make the session per request? Or is there some different tactic that I should be using? What about the lifetime?Where do I set up my sessionfactory? In the global.asax?Can I best create a custom httpmodule or a new servicehostfactory to plug all the goods in?
I've got fluent nhibernate in my application and I'm trying to locate the cause of high memory usage. (I say high, it's 60MB, but it's a web app and it's not very big) Unfortunately it looks like a lot of it is in unmanaged memory, so I started taking things out - and as soon as I took out any calls to nhibernate, the memory usage dropped to 11MB!! Why oh why would it be taking up so much memory? Especially, why would it be taking up unmanaged memory?
I've been 'Googling' this all day and all I can find are posts from people saying "NHibernate eats memory..." and answers that say "no it doesn't, there's no evidence". Are NHibernate people in denial about it?
No records where inserted in my SQL Table after committing the transaction or after the .Flush() method. I checked the code and it follows the correct sequence of codes. I can't seem to find any other way where the error fails.
How can we map a table without having primary key in nHibernate.I have a table which does not contain any primary key, so how can i map this table in .hbm.xml file.
Im currently starting on a project where im using NHibernate for dealing with the DB interactions, and MVC2 (RC) for the front end... and im just wondering if there are any decent tutorials on how to minimize the amount of duplicated validation that needs to be entered to validate thigns in NHibernate and try to mirror those constraints client side.. Ive looked at xVal which looks great, but i cant seem to get it to work and there dont seem to be that many articles about it. Also alot of people are mentioning that its going to become redundant at the MVC level in MVC2 due to the data annotation validation. So im really just after some more information/advice and links on the subject really...
I'm designing my first asp.net web app, using nHibernate as the data provider. i've read a lot about nhibernate in web applications using session-per-request pattern. my application will have a few pages which are 'monitors', meaning- they're updated automatically every few seconds to reflect recent changes to data. in that case, my thought is that opening a session for every request would not make much sense, since I know that an identical request is sure to follow in a few seconds. my thought is that session-per-conversation would make more sense for me, but I'm having trouble finding examples of implementations. I'd appreciate any good resources for how to implement session-per-conversation
I have an ASP.NET v2 website which uses NHibernate for ORM. My current architecture is not that great and I will be changing it after reading some best practices but I wish to still try and figure out my current problem. I have a login screen which creates a ISessionFactory with the connection string set appropriately to the user name and password entered. The SessionFactory is then stored in HttpRuntime.Cache (all objects stored in the HttpRuntime.Cache have an expiration of 30 minutes which is not ideal and may cause issues but hopefully is not relevant to this particular case).
Whenever a data query is made the application tries to retrieve a Session from HttpContext.Current. The first time this occurs no Session is present so one is created from the SessionFactory and stored for future reference. The same Session is therefore is used throughtout the application which is not ideal I believe and it is not explicity closed after each operation. There have been various issues with the application including timeouts which may be associated with not closing connections after each operation. An error that has recently appeared is:
Message: Login failed for user 'myusername'. Type: System.Data.SqlClient.SqlException Source: .Net SqlClient Data Provider Stack Trace: at System.Data.ProviderBase.DbConnectionPool.GetConnection(DbConnection owningObject) at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
This is only after a few minutes of using the application so should not be related to the use of HttpRuntime.Cache. The username in the exception (myusername) does not match the user specified in the connection string! Does anyone have any idea of what could cause this. I was thinking of ConnectionPooling but understand that the connection is made from a pool keyed on user name and password so it shouldn't confuse users. I am changing the application to use an IHttpModule to create a session per request which will be explicity closed after each operation but I would still like to know what causes the current problem.
I have a 'Photo' class and a 'Comment' class. An Photo can have multiple comments assigned to it.I have this configured as a one-to-many relationship within my HBM mapping file, and have set cascade="all-delete-orphan" against the 'Comments' bag within the Photo.hbm.xml mapping file.
However, if I try to delete a Photo which has 1 or more Comments associated with it, I am getting 'The DELETE statement conflicted with the REFERENCE constraint "FK_Comments_Photos"'
I tried a couple of other cascade options against the Comments bag in my Photo.hbm.xml but regardless of what I set it to, I'm getting the same outcome each time. I just want to be able to delete a Photo and have any associated comments automatically delete too.
why the cascade is not happening when I try to delete a Photo with comments associated with it?
UPDATE: The only way I can get the cascade to happen is to configure the 'Delete Rule' within SQL Server against this relationship to 'Cascade', and in doing so means that I don't need to specify any cascade action within my NHibernate Mapping. However, this isn't ideal for me - I'd like to be able to configure the cascade behaviour within the NHibernate Mapping ideally, so I'm still confused as to why it doesn't appear to be taking any notice of my NHibernate cascade setting?
If a client used a license to create a user, I need to update the Used column in the table. As I set ClientId column as the id column for this table in the mapping xml, I am getting TooManyRowsAffectedException. how to set a composite key at mapping level so that NHibernate can udpate based on ClientId and Type.
Something like: Update License SET Used=Used-1 WHERE ClientId='xxx' AND Type=1
I am using xVal with NHibernate Validator and I have a hard time to validate the dates.
First, NHibernate does not have validation for Date/DateTime formatting (except Past and Future). Second, I tried xVal itself (not using NHibernate Validator) but still no chance. I need to validate the date values (let's say in a text box), to make sure it's a valid date. For instance, 13/01/2010 or 11/31/2010 are not valid dates.
I have tried creating new rules for NHibernate Validator by extending a new class, but it needs to be declared in the xVal client side too. I don't like to overwrite the existing scripts, if possible. I also used xval's [DataType(DataType.Date)] but it doesn't check if the date is valid!
I'm yet new to nhibernate and currently have issue calling oracle stored procedure that takes an input parameter and return a SYS_REFCURSOR. Using Nhibernate 3.0 on Oracle 11.1g.
public class AccountTranx { [DisplayName("Entry Date")] public virtual DateTime? TranxDate { get; set; } [DisplayName("Description")] public virtual string TranxDesc { get; set; } [DisplayName("Amount")]
i am having a little problem in mapping all the entities in contained in the namespace "nhibernateTest.Domain" . it basically contains all the Map Classes like , StudentMap, DepartmentMap etc. .. now in case of normal nhibernate what we used to do is :
[Code]....
now what it used to do is . look for all the "*.hbm.xml" files in my namespace and automatically map them...
how to do the same for fluent nHibernate ? so that it looks for all map classes in folder
"nhibernateTest.Domain" ...resolve the namespace "nhibernateTest.Domain"... and automatically map them so that i dont have to create the session separately for diffrent Map classes ?
I have two databases. One from Oracle 10g. Another from Mysql. I have configured my web application with Nhibernate for Oracle and now I am in need of using the MySQL database. So how can i configure the hibernate.cfg.xml so that i can use both of the database at the same application?