InterviewSolution
This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.
| 1. |
Nhibernate Is Deleting My Entire Collection And Recreating It Instead Of Updating The Table? |
|
Answer» This generally happens when NHibernate can't figure out which items changed in the collection. Common causes are:
Thus, to avoid the problem:
This generally happens when NHibernate can't figure out which items changed in the collection. Common causes are: Thus, to avoid the problem: |
|
| 2. |
What Is A Persistent Collection? |
|
Answer» This TERM is used in NHibernate to refer to a collection of its internal class (NHibernate.Collections.Set, List, Bag, etc.) which wraps a user's collection. All collections belonging to ENTITIES returned by NHibernate are PERSISTENT (= wrapped). Entities passed to Save also have their collections wrapped and replaced by the WRAPPERS as a part of the saving process. Persistent collections have a snapshot of their original state and can therefore be updated more efficiently. Collections containing query results are not persistent, they are plain .NET collections (=ArrayList=s). This term is used in NHibernate to refer to a collection of its internal class (NHibernate.Collections.Set, List, Bag, etc.) which wraps a user's collection. All collections belonging to entities returned by NHibernate are persistent (= wrapped). Entities passed to Save also have their collections wrapped and replaced by the wrappers as a part of the saving process. Persistent collections have a snapshot of their original state and can therefore be updated more efficiently. Collections containing query results are not persistent, they are plain .NET collections (=ArrayList=s). |
|
| 3. |
How Do I Translate The Nhibernate Collections To .net Collections? |
|
Answer» The names of the collection mappings is one obvious place where the differences between Java and .NET are shown. Java's collection library has many more options than System.Collection does.
If an order-by attribute is added to the collection mapping element then the concrete collection type will change to one that supports maintaining the order an element was added. For a <bag> it still uses an ArrayList. For the <map> and <set> that have an order-by attribute the concrete collection class changes to a Specialized.ListDictionary and Iesi.Collections.ListSet, respectively. This should be a non-issue since the consumers of your API are using the interfaces IList and Iesi.Collections.ISet. If a SORT attribute is added to the collection mapping element then the concrete collection type will change to one that supports ordering. For the <map> and <set> that have a sort attribute the concrete collection class changes to a SortedList or Iesi.Collections.SortedSet, respectively, that uses the IComparer provided in the sort attribute. This should be a non-issue to the consumers of your API since they are using the interfaces IList and Iesi.Collections.ISet. Using an order-by or sort attribute does have implications on performance for maps and sets as the size of the collections grows. Please read the MSDN documentation about the ListDictionary and SortedList performance implications. There are also some good articles on The Code Project about collections. The names of the collection mappings is one obvious place where the differences between Java and .NET are shown. Java's collection library has many more options than System.Collection does. If an order-by attribute is added to the collection mapping element then the concrete collection type will change to one that supports maintaining the order an element was added. For a <bag> it still uses an ArrayList. For the <map> and <set> that have an order-by attribute the concrete collection class changes to a Specialized.ListDictionary and Iesi.Collections.ListSet, respectively. This should be a non-issue since the consumers of your API are using the interfaces IList and Iesi.Collections.ISet. If a sort attribute is added to the collection mapping element then the concrete collection type will change to one that supports ordering. For the <map> and <set> that have a sort attribute the concrete collection class changes to a SortedList or Iesi.Collections.SortedSet, respectively, that uses the IComparer provided in the sort attribute. This should be a non-issue to the consumers of your API since they are using the interfaces IList and Iesi.Collections.ISet. Using an order-by or sort attribute does have implications on performance for maps and sets as the size of the collections grows. Please read the MSDN documentation about the ListDictionary and SortedList performance implications. There are also some good articles on The Code Project about collections. |
|
| 4. |
Does Nhibernate Modify My Il? If Not, How Do You Know What Has Changed? |
|
Answer» No, it does not modify your IL in ANYWAY. Your IL remains exactly as it was when you COMPILED it. When an object is LOADED by NHibernate the ISession keeps a snapshot of the state of your object. When you FLUSH() the ISession NHibernate compares that snapshot to the current state of the object. The appropriate changes are written to the database. No, it does not modify your IL in anyway. Your IL remains exactly as it was when you compiled it. When an object is loaded by NHibernate the ISession keeps a snapshot of the state of your object. When you Flush() the ISession NHibernate compares that snapshot to the current state of the object. The appropriate changes are written to the database. |
|
| 5. |
Why Doesn't My Proxy Work? |
|
Answer» To be able to create a proxy for a class, the class should have its properties, METHODS and EVENTS declared as virtual. This is not required if the class is PROXIED through an interface it implements (specified using proxy="SomeInterface"). There is no CODE in NHibernate 1.0 to validate your proxy classes, but that will be added in NHibernate 1.1. NHibernate USES the library Castle.DynamicProxy that is part of the Castle Project. DynamicProxy generates IL - not modifying your IL - at runtime for a subclass of your class, or the IL to implement an interface. To be able to create a proxy for a class, the class should have its properties, methods and events declared as virtual. This is not required if the class is proxied through an interface it implements (specified using proxy="SomeInterface"). There is no code in NHibernate 1.0 to validate your proxy classes, but that will be added in NHibernate 1.1. NHibernate uses the library Castle.DynamicProxy that is part of the Castle Project. DynamicProxy generates IL - not modifying your IL - at runtime for a subclass of your class, or the IL to implement an interface. |
|
| 6. |
I've Changed The Mapping File, But Still Get The Same Error I Was Getting Before - Why Isn't Nhibernate Reading The New Mapping File? |
|
Answer» If you compile the mapping files into an assembly as an /EMBEDDED Resource (my personal recommendation) and you use Visual Studio .NET 2003 for DEVELOPMENT, then you need to REBUILD the project, not just build it if all that was changed is a hbm.xml file. VS.NET will not rebuild a project if only an embedded resource has changed - so the assembly STILL contains the OLD hbm.xml file. If you compile the mapping files into an assembly as an /Embedded Resource (my personal recommendation) and you use Visual Studio .NET 2003 for development, then you need to rebuild the project, not just build it if all that was changed is a hbm.xml file. VS.NET will not rebuild a project if only an embedded resource has changed - so the assembly still contains the old hbm.xml file. |
|
| 7. |
I Get An Error Saying No Persisters Found For Myclass? |
|
Answer» This often happens when there is a typo in a mapping file, or when you FORGET to SET the BUILD action for the file to Embedded RESOURCE in VISUAL Studio .NET. This often happens when there is a typo in a mapping file, or when you forget to set the build action for the file to Embedded Resource in Visual Studio .NET. |
|
| 8. |
What Version Of Hibernate Is Nhibernate Ported From? |
|
Answer» NHIBERNATE 1.0 is a port of HIBERNATE 2.1. Some obscure features of Hibernate 2.1 are missing from NHibernate and a few SIMPLE features from Hibernate 3 are PRESENT.
NHibernate 1.0 is a port of Hibernate 2.1. Some obscure features of Hibernate 2.1 are missing from NHibernate and a few simple features from Hibernate 3 are present.
|
|
| 9. |
How Do I Change Nhibernate Configuration Within Burrow On The Fly? |
|
Answer» you can use the following CODE: IFrameworkEnvironment FE = NEW BurrowFramework().BurrowEnvironment; NHibernate.Cfg.Configuration cfg = fe.GetNHConfig("PersistenceUnit1"); ... //do WHATEVER change you need to cfg fe.RebuildSessionFactories(); you can use the following code: IFrameworkEnvironment fe = new BurrowFramework().BurrowEnvironment; NHibernate.Cfg.Configuration cfg = fe.GetNHConfig("PersistenceUnit1"); ... //do whatever change you need to cfg fe.RebuildSessionFactories(); |
|
| 10. |
Does Nhibernate.burrow Create Session And Transaction For Every Http Request? |
|
Answer» Some existing OpenSessionPerView supporting HttpModule SOLUTIONS CREATE UNNECESSARY session and transaction for every http request including REQUESTS for digital assets such as PICTURE and css file. NHibernate.Burrow only creates session and transaction for http request handler that needs. Some existing OpenSessionPerView supporting HttpModule solutions create unnecessary session and transaction for every http request including requests for digital assets such as picture and css file. NHibernate.Burrow only creates session and transaction for http request handler that needs. |
|
| 11. |
What Version Of .net Framework Does Nhibernate.burrow Support? |
|
Answer» NHibernate.Burrow CURRENTLY only WORKS in .NET FRAMEWORK 2.0 NHibernate.Burrow currently only works in .Net Framework 2.0 |
|
| 12. |
What Version Of Nhibernate Is Nhibernate.burrow Using? |
|
Answer» BURROW 1.0 ALPHA 1 is USING NHIBERNATE 2.0 Alpha 1. Burrow 1.0 alpha 1 is using NHibernate 2.0 Alpha 1. |
|
| 13. |
Why I Couldn't Finish A Long Conversation In An Updatepanel In An Ajax.asp.net Project? |
|
Answer» If you KEEP getting a javascript alert window giving the error message "Sys.WebForms.PageReqeustManagerParserErrorExcpetion: The message received from the SERVER could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled." you need to add the following setting into you system.web SECTION in your web.config <pages enableViewStateMac="FALSE" viewStateEncryptionMode="Never" enableEventValidation="false"> If you keep getting a javascript alert window giving the error message "Sys.WebForms.PageReqeustManagerParserErrorExcpetion: The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(), response filters, HttpModules, or server trace is enabled." you need to add the following setting into you system.web section in your web.config <pages enableViewStateMac="false" viewStateEncryptionMode="Never" enableEventValidation="false"> |
|
| 14. |
Is Nhibernate.burrow Compatible With Ajax? |
|
Answer» NHibernate.Burrow is COMPATIBLE with AJAX.Asp.net - the ajax FRAMEWORK PROVIDED by MICROSOFT. NHibernate.Burrow is compatible with Ajax.Asp.net - the ajax framework provided by Microsoft. |
|
| 15. |
How Do I Do Unit Test Under Nhibernate.burrow? |
|
Answer» follows. [SETUP] Or you can USE NHibernate.Burrow.TestUtil.TestBase as your NUnit unit test base class and override TearDowan() and SetUp() method to add your own TearDown and SetUp logic. follows. [SetUp] Or you can use NHibernate.Burrow.TestUtil.TestBase as your NUnit unit test base class and override TearDowan() and SetUp() method to add your own TearDown and SetUp logic. |
|
| 16. |
How Do I Store Data In Httpsession? |
|
Answer» You might already know that you can not store entity in HttpSession in an OpenSessionPerView mode which is what NHibernate.Burrow is using most of the cases. INSTEAD, you can store entity id in session and load the entity with Id EVERY time you use it. Thanks to NHibernate's CACHE, this won't BRING any performance issue to your system. You might already know that you can not store entity in HttpSession in an OpenSessionPerView mode which is what NHibernate.Burrow is using most of the cases. Instead, you can store entity id in session and load the entity with Id every time you use it. Thanks to NHibernate's cache, this won't bring any performance issue to your system. |
|
| 17. |
Why Did I Get This "cannot Find Entity With Id X" Error With My [entityfield] After I Deleted It? |
|
Answer» That's because by default EntityField is using Session.LOAD() to load the entity for you. If you delete the entity, you need to RESET that FIELD to null, if you WANT to save this trouble, you can use [EntityFieldDeletionSafe] instead, it's basically the same EXCEPT that it's using Session.Get(). That's because by default EntityField is using Session.Load() to load the entity for you. If you delete the entity, you need to reset that field to null, if you want to save this trouble, you can use [EntityFieldDeletionSafe] instead, it's basically the same except that it's using Session.Get(). |
|
| 18. |
How Do I Learn More About Nhibernate.burrow? |
| Answer» | |
| 19. |
What's The Major Benefits Offered By Nhibernate.burrow? |
Answer»
|
|
| 20. |
What Is Nhibernate.burrow? |
|
Answer» BURROW is a light weight middleware developed to support .Net applications using NHibernate (maybe also REFERRED as NH in this article) as ORM FRAMEWORK. Using Asp.net with NHibernate could be a challenge because of the fact that NHibernate is a STATEFUL environment while Asp.net is a stateless framework. Burrow can help solve this conflict by providing advanced and SMART session/transaction management and other facilitates. Burrow is a light weight middleware developed to support .Net applications using NHibernate (maybe also referred as NH in this article) as ORM framework. Using Asp.net with NHibernate could be a challenge because of the fact that NHibernate is a stateful environment while Asp.net is a stateless framework. Burrow can help solve this conflict by providing advanced and smart session/transaction management and other facilitates. |
|
| 21. |
How To Configure Nhibernate? |
|
Answer» CONFIGURATION files and mapping files(.hbm.xml) are used by Configuration class to create the SessionFactory, which in turn CREATES the Session INSTANCE . Session instance are primary interface for persistence service. config file is used to specify connection details and mapping files used to map persistant objects to a relational database. It is best practice to store each object in an individual mapping file. SessionFactory is nhibernate concept of a single datastore and is threadsafe so that many THREADS can access it concurrently, SessionFactory is usually built only once at startup Configuration files and mapping files(.hbm.xml) are used by Configuration class to create the SessionFactory, which in turn creates the Session instance . Session instance are primary interface for persistence service. config file is used to specify connection details and mapping files used to map persistant objects to a relational database. It is best practice to store each object in an individual mapping file. SessionFactory is nhibernate concept of a single datastore and is threadsafe so that many threads can access it concurrently, SessionFactory is usually built only once at startup |
|
| 22. |
What Is Difference Between Session.get() And Session.load()? |
|
Answer» Both Session.GET() and Session.Load() method create a persistent object by loading the REQUIRED object from the database. But if there was not an object in database, then ‘Load’ method THROWS an exception where as Get method RETURNS null. Both Session.Get() and Session.Load() method create a persistent object by loading the required object from the database. But if there was not an object in database, then ‘Load’ method throws an exception where as Get method returns null. |
|
| 23. |
How Do You Switch Between Relational Databases Without Code Changes? |
|
Answer» By using hibernate SQL dialects, we can SWITCH databases. Hibernate will GENERATE APPROPRIATE hql queries BASED on the dialect defined. By using hibernate SQL dialects, we can switch databases. Hibernate will generate appropriate hql queries based on the dialect defined. |
|
| 24. |
Explain About Nhibernate Mapping Files? |
|
Answer» Mapping files form core of any database. These files contain field to field mapping, usually this mapping occurs between classes and ATTRIBUTES. Sample mapping file: <?xml version="1.0" encoding="utf-8" ?> No NEED to specify column name if database column name is same as property . <property name="Name" column="database-column-name" /> Also, right-click on "FirstSample.hbm.xml", select "Properties" and change the "Build ACTION" to "Embedded Resource". The mapping file will now be a part of the Asssembly. Mapping files form core of any database. These files contain field to field mapping, usually this mapping occurs between classes and attributes. Sample mapping file: <?xml version="1.0" encoding="utf-8" ?> No need to specify column name if database column name is same as property . <property name="Name" column="database-column-name" /> Also, right-click on "FirstSample.hbm.xml", select "Properties" and change the "Build Action" to "Embedded Resource". The mapping file will now be a part of the Asssembly. |
|
| 25. |
Define Cascade In Nhibernate Mapping File? |
|
Answer» Cascade: enable OPERATIONS to cascade to child entities. cascade=”all | NONE | save-update | delete | all-delete orphan” all: when an object is save/update/delete, check the ASSOCIATIONS and save/update/delete all objects found. none: do not do any cascades, let user handles them by themselves. save-update: when the object is saved/updated, check the associations and save/update any object that require it. delete: when the object is deleted, delete all the objects in the association. all-delete-orphan: when an object is save/update/delete, check the associations and save/update/delete all objects found. in addition to this, when an object is removed from the association and not ASSOCIATED with another object, delete the orphan object also. Cascade: enable operations to cascade to child entities. cascade=”all | none | save-update | delete | all-delete orphan” all: when an object is save/update/delete, check the associations and save/update/delete all objects found. none: do not do any cascades, let user handles them by themselves. save-update: when the object is saved/updated, check the associations and save/update any object that require it. delete: when the object is deleted, delete all the objects in the association. all-delete-orphan: when an object is save/update/delete, check the associations and save/update/delete all objects found. in addition to this, when an object is removed from the association and not associated with another object, delete the orphan object also. |
|