Login

Username

Password





Register   Reset password

This is a read-only archive of the forum.

# XscorX 10/31/2007 10:36 AM
I am trying to make a mapping for 2 new classes Company, Country

Where company has many users and country contains many companies, but each user exists in one company and each company exists in one country.

After i did the mapping i tried running the project but an error occurred

[Error]
Exception Details: System.Xml.Schema.XmlSchemaException: The 'lazy' attribute is not declared.
[/Error]

Sorry but I am new to Nhibrnate and I tried searching for this error but in vain if any one can help me I will be very grateful
((?xml version="1.0" encoding="utf-8" ?))
((hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"))
	((class name="Cuyahoga.Core.Domain.Company, Cuyahoga.Core" table="cuyahoga_company"))

		((cache usage="read-write" /))

		((id name="Id" column="company_Id" type="Int32" unsaved-value="0"))
			((generator class="identity"/))
		((/id))

		((property name="CompanyName" column="company_name"		type="String" length="100" /))
		((property name="Address1" column="address1" type="String" length="100" /))
		((property name="Address2" column="address2" type="String" length="100" /))
		((property name="Phone" column="phone" type="String" length="25" /))
		((property name="Fax" column="fax" type="String" length="25" /))
		((property name="City" column="city" type="String" length="100" /))
		((property name="Website" column="website" type="String" length="100" /))
		((property name="State" column="state" type="String" length="50" /))
		((property name="PostalCode" column="postalcode" 	type="String" length="20" /))
		((property name="Industry" column="industry" type="String" length="250" /))
		((property name="InsertTimestamp" column="inserttimestamp" type="DateTime"  /))
		((property name="UpdateTimestamp" column="updatetimestamp" type="DateTime"  /))
		
		((bag name="Users" cascade="none" lazy="true"))
			((key column="companyId"/))
			((one-to-many class="Cuyahoga.Core.Domain.User, Cuyahoga.Core.Domain.Company " /))
		((/bag))

		
			  ((many-to-one name="CompanyCountry" class="Cuyahoga.Core.Domain.Country, Cuyahoga.Core.Domain.Company" column="countryid" cascade="all"/))
	((/class))
((/hibernate-mapping))


((?xml version="1.0" encoding="utf-8" ?)) 
((hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"))
	((class name="Cuyahoga.Core.Domain.Country, Cuyahoga.Core" table="cm_country"))
	
		((cache usage="read-write" /))
		
		((id name="Id" column="Country_Id" type="Int32" unsaved-value="0"))
			((generator class="identity"/))
		((/id))
		
		((property name="Name" column="Country_Name" type="String" length="50" /))
		((property name="Code" column="Country_Code" type="String" length="50" /))

		((bag name="Companies" cascade="all" lazy="true"))
				  ((key column="countryid"/))
			((one-to-many class="Cuyahoga.Core.Domain.Company, Cuyahoga.Core.Domain.Country"  /))
		((/bag))
	((/class))
((/hibernate-mapping))

((?xml version="1.0" encoding="utf-8" ?)) 
((hibernate-mapping xmlns="urn:nhibernate-mapping-2.0"))
	((class name="Cuyahoga.Core.Domain.User, Cuyahoga.Core" table="cuyahoga_user"
		proxy="Cuyahoga.Core.Domain.User, Cuyahoga.Core"))

		((cache usage="read-write" /))
		
		((id name="Id" column="userid" type="Int32" unsaved-value="-1"))
			((generator class="native"))
				((param name="sequence"))cuyahoga_user_userid_seq((/param))
			((/generator))
		((/id))
		
		((timestamp name="UpdateTimestamp" column="updatetimestamp" /))

		((property name="UserName" column="username" type="String" length="50" /))
		((property name="Password" column="password" type="String" length="100" /))		
		((property name="FirstName" column="firstname" type="String" length="100" not-null="false" /))
		((property name="LastName" column="lastname" type="String" length="100" not-null="false" /))
		((property name="Title" column="title" type="String" length="50" /))
		((property name="Email" column="email" type="String" length="100" /))
		((property name="Website" column="website" type="String" length="100" /))
		((property name="TimeZone" column="timezone" type="Int32" /))
		((property name="IsActive" column="isactive" type="Boolean" length="100" /))
		((property name="LastLogin" column="lastlogin" type="Nullables.NHibernate.NullableDateTimeType, Nullables.NHibernate" /))
		((property name="LastIp" column="lastip" type="String" length="40" /))
		((property name="InsertTimestamp" column="inserttimestamp" type="DateTime" /))

		((many-to-one name="UserCompany" class="Cuyahoga.Core.Domain.Company, Cuyahoga.Core.Domain.User" column="companyid" cascade="all" lazy="true"/))
		
		((bag name="Roles" table="cuyahoga_userrole" cascade="none" lazy="true"))
			((cache usage="read-write" /))
			((key column="userid" /))
			((many-to-many class="Cuyahoga.Core.Domain.Role, Cuyahoga.Core" column="roleid" outer-join="true" /))
		((/bag))
	((/class))
((/hibernate-mapping))

# martijnb 10/31/2007 1:58 PM
Haven't seen this error before. I thought all 'lazy' attributes were optional, but apparently not.
Maybe, if you ask this on the NHibernate forum, you can get a better answer.
# XscorX 10/31/2007 4:08 PM
thanks for the hint
here is the error
((many-to-one name="UserCompany" class="Cuyahoga.Core.Domain.Company, Cuyahoga.Core.Domain.User" column="companyid" cascade="all" lazy="true"/))

sorry as i am still new to NHibrnate
# martijnb 10/31/2007 9:39 PM
Ah, you have a lazy attribute on a many-one relation. This won't work because you have to mark the many-one related class itself as lazy (which is the default since NH 1.2, btw).
So removing the lazy attribute here will probably solve the issue.

# XscorX 11/4/2007 1:30 PM (edited 11/4/2007 1:46 PM)
ok another NHibrnate error:

i am using Ms SQL 2005 when i try to add a new company the transaction failed bec of the id field

here are the maps i tried:
((id name="Id" column="companyid" type="Int32" unsaved-value="-1"))
			((generator class="native"/))
((/id))
((id name="Id" column="companyid" type="Int32" unsaved-value="-1"))
			((generator class="native"))
			((/generator))
((/id))
((id name="Id" column="companyid" type="Int32" unsaved-value="-1"))
			((generator class="identity"/r))
((/id))

I do not know how you did this
((id name="Id" column="userid" type="Int32" unsaved-value="-1"))
			((generator class="native"))
				((param name="sequence"))cuyahoga_user_userid_seq((/param))
			((/generator))
		((/id))

i even tried this
((id name="Id" column="companyid" type="Int32" unsaved-value="-1"))
			((generator class="native"))
				((param name="sequence"))cuyahoga_user_userid_seq((/param))
			((/generator))
		((/id))

when i tried creating a sequance in sql 2005 it gave an error about the sequance word. any idea how i can solve this please.
# martijnb 11/4/2007 2:18 PM
For SQL Server and identity fields, both 'native' and 'identity' should work. Also make sure that the unsaved value matches the initial value in the class.