nhibernate, could not resolve property QueryOver only one table - nhibernate

I have found a dozen of question similar to mine but none of them offered a solution to my problem.
Thank you in advance
Ok,
I have this class
public class User : IEntity
{
private int id;
public virtual int Id { get { return id; } }
private string email;
public virtual string Email
{
get { return email; }
//private set { email = value; }
}
private string password;
public virtual string Password
{
get { return password; }
//private set { password = value; }
}
private bool isActive;
public virtual bool IsActive
{
get { return isActive; }
//private set { isActive = value; }
}
private bool isRegistered;
public virtual bool IsRegistered
{
get { return isRegistered; }
//private set { isRegistered = value; }
}
private bool hasRequestedApplication;
public virtual bool HasRequestedApplication
{
get { return hasRequestedApplication; }
//private set { hasRequestedApplication = value; }
}
private ContactInfo contactInformation;
public virtual ContactInfo ContactInformation
{
get { return contactInformation; }
//private set { contactInformation = value; }
}
public User(string email)
{
this.email = email;
}
public User(string email, string password):this(email)
{
this.password = password;
}
public User()
{ }
}
this is the mapping....
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Domain"
namespace="Domain.User" default-access="field">
<class name="User" table="[User]">
<id name="id" column="UserID">
<generator class="identity" />
</id>
<property name="email" column="Email" not-null="true"></property>
<property name="password" column="HashedPassword" not-null="false"></property>
<property name="isRegistered" column="IsRegistered" not-null="true"></property>
<property name="isActive" column="IsActive" not-null="true"></property>
<property name="hasRequestedApplication" column="HasRequestedApplication" not-null="true"></property>
<one-to-one name="contactInformation" class="Domain.User.ContactInfo"/>
</class>
</hibernate-mapping>
and this is how i am calling it
public class UserRepository: IUserRepository
{
Func<ISession> session;
public UserRepository(Func<ISession> _session)
{
session = _session;
}
[Transaction]
public User FindByEmail(string emailAddress)
{
using (var tx = session())
{
return tx.QueryOver<User>().Where(u => u.Email == emailAddress).SingleOrDefault();
}
}
}
Error...
{"could not resolve property: Email of: Domain.User.User"}
StackTrace...
at NHibernate.Persister.Entity.AbstractPropertyMapping.ToType(String propertyName)
at NHibernate.Persister.Entity.AbstractEntityPersister.GetSubclassPropertyTableNumber(String propertyPath)
at NHibernate.Persister.Entity.BasicEntityPropertyMapping.ToColumns(String alias, String propertyName)
at NHibernate.Persister.Entity.AbstractEntityPersister.ToColumns(String alias, String propertyName)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetColumns(ICriteria subcriteria, String propertyName)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetColumnsUsingProjection(ICriteria subcriteria, String propertyName)
at NHibernate.Criterion.CriterionUtil.GetColumnNamesUsingPropertyName(ICriteriaQuery criteriaQuery, ICriteria criteria, String propertyName, Object value, ICriterion critertion)
at NHibernate.Criterion.SimpleExpression.ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery, IDictionary2 enabledFilters)
at NHibernate.Loader.Criteria.CriteriaQueryTranslator.GetWhereCondition(IDictionary2 enabledFilters)
at NHibernate.Loader.Criteria.CriteriaJoinWalker..ctor(IOuterJoinLoadable persister, CriteriaQueryTranslator translator, ISessionFactoryImplementor factory, ICriteria criteria, String rootEntityName, IDictionary2 enabledFilters)
at NHibernate.Loader.Criteria.CriteriaLoader..ctor(IOuterJoinLoadable persister, ISessionFactoryImplementor factory, CriteriaImpl rootCriteria, String rootEntityName, IDictionary2 enabledFilters)
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
at NHibernate.Impl.CriteriaImpl.List(IList results)
at NHibernate.Impl.CriteriaImpl.UniqueResultT
at NHibernate.Criterion.QueryOver1.SingleOrDefault()
at NHibernate.Criterion.QueryOver1.NHibernate.IQueryOver.SingleOrDefault()
at DataObjects.NHibernate.UserRepository.FindByEmail(String emailAddress) in E:\Projects\DataObjects.NHibernate\UserRepository.cs:line 26
at Castle.Proxies.Invocations.IUserRepository_FindByEmail.InvokeMethodOnTarget()
at Castle.DynamicProxy.AbstractInvocation.Proceed()
at Castle.Facilities.AutoTx.TransactionInterceptor.SynchronizedCase(IInvocation invocation, ITransaction transaction) in d:\BuildAgent-03\work\9844bdf039249947\src\Castle.Facilities.AutoTx\TransactionInterceptor.cs:line 137
EDIT:
OK. Solved to some extent. I changed all my properties and components name to capital in my mapping.
Instead of...
<property name="email" column="emailaddress" />
set it to...
<property name="Email" column="emailaddress" />
and it works. Now, is that a guarantee that NHibernate is populating/reading my properties via the fields? I hope so.

This should help: Change the settings to be different for get and set
<hibernate-mapping ... default-access="field.camelcase">
and map the properties:
<property name="Email" column="emailaddress" />
NHibernate will use field for set and the Property for get. This QueryOver:
return tx.QueryOver<User>()
.Where(u => u.Email == emailAddress)
.SingleOrDefault();
...will work now

I believe the "name" of the properties in your mapping should match the case of the public virtual properties in your class. Try changing <property name="email"... to <property name="Email"... and so on.

Related

"Could not locate cfg.xml resource [hibernate.cfg.xml]" error

When I run my createStudentDemo class I get the following error:
INFO: HHH000412: Hibernate Core {5.4.11.Final}
Exception in thread "main"
org.hibernate.internal.util.config.ConfigurationException: Could not
locate cfg.xml resource [hibernate.cfg.xml] at
org.hibernate.boot.cfgxml.internal.ConfigLoader.loadConfigXmlResource(ConfigLoader.java:53) at
org.hibernate.boot.registry.StandardServiceRegistryBuilder.configure(StandardServiceRegistryBuilder.java:215) at org.hibernate.cfg.Configuration.configure(Configuration.java:258)
at org.hibernate.cfg.Configuration.configure(Configuration.java:244)
at
com.luv2code.hibernate.demo.CreateStudentDemo.main(CreateStudentDemo.java:15)
I don't understand why I have this error.
Here is the code of my createStudentDemo class:
package com.luv2code.hibernate.demo;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import com.luv2code.hibernate.demo.entity.Student;
public class CreateStudentDemo {
public static void main(String[] args) {
// create session factory
SessionFactory factory= new Configuration()
.configure("hibernate.cfg.xml")
.addAnnotatedClass(Student.class)
.buildSessionFactory();
// create session
Session session = factory.getCurrentSession();
try {
//create a student object
System.out.println("creating new student object");
Student tempStudent = new Student("Paul", "Wall", "paul#luv2code.com");
//start a transaction
session.beginTransaction();
// save the student object
System.out.println("Saving the student...");
session.save(tempStudent);
//commit transaction
session.getTransaction().commit();
System.out.println("Done !");
}
finally {
factory.close();
}
}
}
and here is the code for my class student:
package com.luv2code.hibernate.demo.entity;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
#Entity
#Table(name="student")
public class Student {
public Student() {
}
#Id
#Column(name="id")
private int id;
#Column(name="first_name")
private String firstName;
#Column(name="last_name")
private String lastName;
#Column(name="email")
private String email;
public Student(String firstName, String lastName, String email) {
this.firstName = firstName;
this.lastName = lastName;
this.email = email;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getLastName() {
return lastName;
}
public void setLastName(String lastName) {
this.lastName = lastName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
#Override
public String toString() {
return "Student [id=" + id + ", firstName=" + firstName + ", lastName=" + lastName + ", email=" + email + "]";
}
}
and here is the code of my hibernate.cfg.xml file:
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- JDBC Database connection settings -->
<property name="connection.driver_class">com.mysql.cj.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/hb_student_tracker?useSSL=false&serverTimezone=UTC</property>
<property name="connection.username">hbstudent</property>
<property name="connection.password">hbstudent</property>
<!-- JDBC connection pool settings ... using built-in test pool -->
<property name="connection.pool_size">1</property>
<!-- Select our SQL dialect -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Echo the SQL to stdout -->
<property name="show_sql">true</property>
<!-- Set the current session context -->
<property name="current_session_context_class">thread</property>
</session-factory>
</hibernate-configuration>
and here is the location of my files:
Can someone help me please?
You hibernate.cfg.xml should be in classpath. Put it in src folder.

Spring mvc MappingSqlQuery Property 'sql' is required

I work with Netbeans, Spring MVC and Oracle.
I want to use MappingSqlQuery to execute oracle sql. This is the java class which implements MappingSqlQuery
public class SelectAllDepartamentos extends MappingSqlQuery<Departamento> {
private static final String SQL_SELECT_DEPT =
"SELECT DEPT_NO, DNOMBRE, LOC FROM DEPT";
public SelectAllDepartamentos() {
}
public SelectAllDepartamentos(DataSource dataSource) {
super(dataSource,SQL_SELECT_DEPT);
}
#Override
protected Departamento mapRow(ResultSet rs, int i) throws SQLException {
Departamento dept = new Departamento();
dept.setNumero(rs.getInt("DEPT_NO"));
dept.setNombre(rs.getString("DNOMBRE"));
dept.setLocalidad(rs.getString("LOC"));
return dept;
}
}
The class which use SelectAllDepartamentos is . The method that I use is findAll
public class JdbcDepartamentoDao1 implements InitializingBean,DepartamentoDao{
private javax.sql.DataSource dataSource;
private JdbcTemplate jdbcTemplate;
private SelectAllDepartamentos selectdepartamentos;
public JdbcDepartamentoDao1() {
}
public JdbcDepartamentoDao1(javax.sql.DataSource dataSource) {
this.dataSource = dataSource;
}
public void setDataSource(javax.sql.DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.selectdepartamentos = new SelectAllDepartamentos();
}
#Override
public List<Departamento> findAll() {
return this.selectdepartamentos.execute();
}
#Override
public List<Departamento> findByLocalidad(String localidad) {
return null;
}
#Override
public String findById(int iddepartamento) {
String nombre = jdbcTemplate.queryForObject("SELECT DNOMBRE from DEPT WHERE DEPT_NO = ?",
new Object[]{iddepartamento},String.class);
return nombre;
}
#Override
public void insertarDepartamento(Departamento departamento) {
}
#Override
public void modificarDepartamento(Departamento departamento) {
}
#Override
public void eliminarDepartamento(Departamento departamento) {
}
#Override
public void afterPropertiesSet() throws Exception {
if (dataSource == null){
throw new BeanCreationException("Debe establece el dataSource ContactDao");
}
}
}
My application-context.xml is
<?xml version='1.0' encoding='UTF-8' ?>
<!-- was: <?xml version="1.0" encoding="UTF-8"?> -->
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd
http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd">
<bean id="propertyConfigurer"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"
p:location="/WEB-INF/jdbc.properties" />
<bean id="departamentoDao" class="dao.JdbcDepartamentoDao1">
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="dataSource"
class="org.springframework.jdbc.datasource.DriverManagerDataSource"
p:driverClassName="${jdbc.driverClassName}"
p:url="${jdbc.url}"
p:username="${jdbc.username}"
p:password="${jdbc.password}" />
<!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
<bean id="selectAllDepartamentos" class="modelos.SelectAllDepartamentos">
<property name="dataSource" ref="dataSource"></property>
<constructor-arg type="DataSource" ref="dataSource"></constructor-arg>
</bean>
</beans>
When I executed the method findAll
#Override
public List<Departamento> findAll() {
return this.selectdepartamentos.execute();
}
I get the error
Remove
/*public void setDataSource(javax.sql.DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.selectdepartamentos = new SelectAllDepartamentos();
}*/
Change to arg
<bean id="departamentoDao" class="dao.JdbcDepartamentoDao1">
<constructor-arg ref="dataSource" />
</bean>
Update constructor
public JdbcDepartamentoDao1(javax.sql.DataSource dataSource) {
this.dataSource = dataSource;
this.jdbcTemplate = new JdbcTemplate(dataSource);
this.selectdepartamentos = new SelectAllDepartamentos();
}

Mapping a struct as Id in nhibernate

I have the following struct and class:
public struct DepartmentId{
public int Value {get; set;}
}
public class Department{
public virtual DepartmentId Id{get;set;}
public virtual string Name {get; set;}
}
I created a mapping file for Department as follows:
public class DepartmentMapping : ClassMapping<Department>{
public DepartmentMapping{
Table("Department");
Id(dept => dept.Id, mapper => {
mapper.Column("Id");
mapper.Type(new DepartmentIdType());
});
Property(dept => dept.Name, mapper => mapper.Column("Name"));
}
}
where DepartmentIdType implements IIdentifierType:
class DepartmentIdType : PrimitiveType, IIdentifierType
{
public DepartmentIdType() : base(SqlTypeFactory.Int32)
{
}
public override object DeepCopy(object val, EntityMode entityMode, ISessionFactoryImplementor factory)
{
return val;
}
public override object Replace(object original, object current, ISessionImplementor session, object owner, IDictionary copiedAlready)
{
return original;
}
public override Type ReturnedClass
{
get { return typeof(DepartmentId); }
}
public object StringToObject(string xml)
{
return new DepartmentId {Value = int.Parse(xml)};
}
public override string Name
{
get { return typeof(DepartmentId).Name; }
}
public override void Set(IDbCommand cmd, object value, int index)
{
var id = (DepartmentId) value;
((IDataParameter) cmd.Parameters[index]).Value = id.Value;
}
public override object Get(IDataReader rs, int index)
{
int value = rs.GetInt32(index);
return new DepartmentId {Value = value};
}
public override object Get(IDataReader rs, string name)
{
return Get(rs, rs.GetOrdinal(name));
}
public override string ToString(object val)
{
if (val == null) return "";
return val.ToString();
}
public override object FromStringValue(string xml)
{
return new DepartmentId {Value = Int32.Parse(xml)};
}
public override object DefaultValue
{
get { return new DepartmentId {Value = 0}; }
}
public override string ObjectToSQLString(object value, NHibernate.Dialect.Dialect dialect)
{
return value.ToString();
}
public override Type PrimitiveClass
{
get { return typeof(DepartmentId); }
}
}
However, at the time of creating the HbmMapping, I get the following error:
Could not compile the mapping document: mapping_by_code
NHibernate.MappingException: Could not compile the mapping document:
mapping_by_code ---> NHibernate.MappingException:
Could not determine type for: Demo.Models.DepartmentId, Demo.Models,
for columns: NHibernate.Mapping.Column(Id)
at NHibernate.Mapping.SimpleValue.get_Type()
at NHibernate.Cfg.XmlHbmBinding.ClassIdBinder.CreateIdentifierProperty(HbmId idSchema, PersistentClass rootClass, SimpleValue id)
at NHibernate.Cfg.XmlHbmBinding.ClassIdBinder.BindId(HbmId idSchema, PersistentClass rootClass, Table table)
at NHibernate.Cfg.XmlHbmBinding.RootClassBinder.Bind(HbmClass classSchema, IDictionary`2 inheritedMetas)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddRootClasses(HbmClass rootClass, IDictionary`2 inheritedMetas)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.AddEntitiesMappings(HbmMapping mappingSchema, IDictionary`2 inheritedMetas)
at NHibernate.Cfg.XmlHbmBinding.MappingRootBinder.Bind(HbmMapping mappingSchema)
at NHibernate.Cfg.Configuration.AddDeserializedMapping(HbmMapping mappingDocument, String documentFileName)
How do I fix this issue (without changing DepartmentId from struct to class)?
Thanks in advance for your help.
I suggest using class instead of struct and ComponentAsId instead of Id method for this case. If you don't use id generator it is a straightforward approach without any hacking.
public class DepartmentMapping : ClassMapping<Department> {
public DepartmentMapping{
Table("Department");
ComponentAsId(dept => dept.Id);
Property(dept => dept.Name, mapper => mapper.Column("Name"));
}}
public class DepartmentIdMapping : ComponentMapping<DepartmentId> {
public DepartmentIdMapping{
Property(x=> x.Value, mapper => mapper.Column("Id"));
}}
I tried your approach when investigating this strong typed ids together with id generation but I finally decided to implement custom Hi/Lo generator and use NHibernate assigned ids.
I'm just going to put this here for a reference.
In XML mapping, I did this through mapping as a composite id:
<class name"Department" ... >
<composite-id name="Id" access="property"
class="DepartmentId">
<key-property name="Value"
column="Id"
access="property"
type="System.Int32"/>
</composite-id>
... other stuff
</class>

composite Key and inheritance

i have the following classes and mappings
abstract class BaseClass
{
public virtual int Keypart1 { get; set; }
public virtual int Keypart2 { get; set; }
// overridden Equals() and GetHashCode()
}
class InheritingClass : BaseClass
{
}
class BaseClassMap : ClassMap<BaseClass>
{
public BaseClassMap()
{
CompositeId()
.KeyProperty(x => x.Keypart1)
.KeyProperty(x => x.Keypart2);
}
}
class InheritingClassMap : SubclassMap<InheritingClass>
{
public InheritingClassMap()
{
KeyColumn("Keypart1");
KeyColumn("Keypart2");
}
}
inserting, updating and session.Get() work fine but querying like
var result = session.CreateCriteria<InheritingClass>().List<InheritingClass>();
throws
NHibernate.InstantiationException: Cannot instantiate abstract class or interface: ConsoleApplication1.BaseClass
bei NHibernate.Tuple.PocoInstantiator.Instantiate()
bei NHibernate.Tuple.Component.AbstractComponentTuplizer.Instantiate()
bei NHibernate.Type.ComponentType.Instantiate(EntityMode entityMode)
bei NHibernate.Type.ComponentType.Instantiate(Object parent, ISessionImplementor session)
bei NHibernate.Type.EmbeddedComponentType.Instantiate(Object parent, ISessionImplementor session)
bei NHibernate.Type.ComponentType.ResolveIdentifier(Object value, ISessionImplementor session, Object owner)
bei NHibernate.Type.ComponentType.NullSafeGet(IDataReader rs, String[] names, ISessionImplementor session, Object owner)
bei NHibernate.Loader.Loader.GetKeyFromResultSet(Int32 i, IEntityPersister persister, Object id, IDataReader rs, ISessionImplementor session)
bei NHibernate.Loader.Loader.GetRowFromResultSet(IDataReader resultSet, ISessionImplementor session, QueryParameters queryParameters, LockMode[] lockModeArray, EntityKey optionalObjectKey, IList hydratedObjects, EntityKey[] keys, Boolean returnProxies)
...
it seems NH tries to instantiate the abstract baseclass as a compositekey and fails. Can i somehow work around that?
UPDATE: my testcode
var config = Fluently.Configure()
.Database(SQLiteConfiguration.Standard.InMemory().ShowSql().FormatSql())
.Mappings(m => m.FluentMappings
.Add<BaseClassMap>()
.Add<InheritingClassMap>()
)
.BuildConfiguration();
var sf = config.BuildSessionFactory();
using (var session = sf.OpenSession())
{
new SchemaExport(config).Execute(false, true, false, session.Connection, null);
var obj = new InheritingClass
{
Keypart1 = 1,
Keypart2 = 2,
};
session.Save(obj);
session.Flush();
session.Clear();
// throws here
var result = session.CreateCriteria<InheritingClass>().List<InheritingClass>();
}
How does your database look like? According to your mapping, you are using a table-per-subclass mapping. In this case NHibernate will try to create an instance of BaseClass if no row is found in the table of InheritingClass.
edit: There is a abstract="true" attribute for a <class> in NHibernate mapping which might fix your problem. But it seems like this isn't exposed in Fluent NHibernate for a ClassMap, only for SubclassMap (which won't help you).
But maybe you could also fix the problem by using a component for the composite ID (so that NHibernate doesn't need to create a BaseClass object for its EntityKey. See here for infos about that.
thx to cremor this is what i end up with
abstract class BaseClass
{
public virtual BaseClassId Key { get; set; }
}
class BaseClassId
{
public virtual int Keypart1 { get; set; }
public virtual int Keypart2 { get; set; }
public override bool Equals(object obj)
{
var other = obj as BaseClassId;
return (other != null) && (Keypart1 == other.Keypart1) && (Keypart2 == other.Keypart2);
}
public override int GetHashCode()
{
unchecked
{
return Keypart1 + Keypart2;
}
}
}
// mapping
CompositeId(b => b.Key)
.KeyProperty(x => x.Keypart1)
.KeyProperty(x => x.Keypart2);
var obj = new InheritingClass
{
Key = new BaseClassId
{
Keypart1 = 1,
Keypart2 = 2,
}
};

one-to-many relationship with table having composite key

This is the full code for mapping of the tables I am doing. But dont know why I am getting
java heap space error. I am using Jboss server and the exact error message is java.lang.OutOfMemoryError: Java heap space.
package com.mercer.chat.app.dataobject;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class MHRContChatSessionDO {
private Long id;
private String chatBucketHeadline;
private String preChatLongHeadline;
private String postChatLongHeadline;
private String preChatSummary;
private String postChatSummary;
private String chatBucketImage;
private String chatLogPath;
private Integer roomId;
private List<MHRContChatAlertsDO> chatAlerts;
public MHRContChatSessionDO() {
super();
}
public MHRContChatSessionDO(Long id, String chatBucketHeadline, String preChatLongHeadline,
String postChatLongHeadline, String preChatSummary, String postChatSummary, String chatBucketImage,
String chatLogPath,Integer roomId, List<MHRContChatAlertsDO> chatAlerts) {
super();
this.id = id;
this.chatBucketHeadline = chatBucketHeadline;
this.preChatLongHeadline = preChatLongHeadline;
this.postChatLongHeadline = postChatLongHeadline;
this.preChatSummary = preChatSummary;
this.postChatSummary = postChatSummary;
this.chatBucketImage = chatBucketImage;
this.chatLogPath = chatLogPath;
this.roomId = roomId;
this.chatAlerts = chatAlerts;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getChatBucketHeadline() {
return chatBucketHeadline;
}
public void setChatBucketHeadline(String chatBucketHeadline) {
this.chatBucketHeadline = chatBucketHeadline;
}
public String getPreChatLongHeadline() {
return preChatLongHeadline;
}
public void setPreChatLongHeadline(String preChatLongHeadline) {
this.preChatLongHeadline = preChatLongHeadline;
}
public String getPostChatLongHeadline() {
return postChatLongHeadline;
}
public void setPostChatLongHeadline(String postChatLongHeadline) {
this.postChatLongHeadline = postChatLongHeadline;
}
public String getPreChatSummary() {
return preChatSummary;
}
public void setPreChatSummary(String preChatSummary) {
this.preChatSummary = preChatSummary;
}
public String getPostChatSummary() {
return postChatSummary;
}
public void setPostChatSummary(String postChatSummary) {
this.postChatSummary = postChatSummary;
}
public String getChatBucketImage() {
return chatBucketImage;
}
public void setChatBucketImage(String chatBucketImage) {
this.chatBucketImage = chatBucketImage;
}
public String getChatLogPath() {
return chatLogPath;
}
public void setChatLogPath(String chatLogPath) {
this.chatLogPath = chatLogPath;
}
public Integer getRoomId() {
return roomId;
}
public void setRoomId(Integer roomId) {
this.roomId = roomId;
}
public List<MHRContChatAlertsDO> getChatAlerts() {
return chatAlerts;
}
public void setChatAlerts(List<MHRContChatAlertsDO> chatAlerts) {
this.chatAlerts = chatAlerts;
}
}
public class MHRContChatAlertsDO implements Serializable {
private Long id;
private String userId;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getUserId() {
return userId;
}
public void setUserId(String userId) {
this.userId = userId;
}
public MHRContChatAlertsDO() {
}
public MHRContChatAlertsDO(Long id,String userId) {
this.id=id;
this.userId=userId;
}
#Override
public boolean equals(Object arg0) {
if(arg0 == null) return false;
if(!(arg0 instanceof MHRContChatAlertsDO)) return false;
MHRContChatAlertsDO arg1 = (MHRContChatAlertsDO) arg0;
return (this.id.longValue() == arg1.getId().longValue()) && (this.userId.equals(arg1.getUserId()) );
}
#Override
public int hashCode() {
int hsCode;
hsCode = id.hashCode();
hsCode = 19 * hsCode+ userId.hashCode();
return hsCode;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping default-lazy="true">
<class name="com.mercer.chat.app.dataobject.MHRContChatSessionDO"
table="QA_TEST2">
<cache usage="read-only" include="all"/>
<id name="id" type="java.lang.Long">
<column name="ID_CHAT_SESSION" precision="22" scale="0" />
<generator class="assigned" />
</id>
<property name="chatBucketHeadline" type="string">
<column name="CHAT_BUCKET_HEADLINE" />
</property>
<property name="preChatLongHeadline" type="string">
<column name="PRE_CHAT_LONGHEADLINE" scale="0" />
</property>
<property name="postChatLongHeadline" type="string">
<column name="POST_CHAT_LONGHEADLINE" />
</property>
<property name="preChatSummary" type="string">
<column name="PRE_CHAT_SUMMARY" />
</property>
<property name="postChatSummary" type="string">
<column name="POST_CHAT_SUMMARY" not-null="true" />
</property>
<property name="chatBucketImage" type="string">
<column name="CHAT_BUCKET_IMAGE_PATH" />
</property>
<property name="chatLogPath" type="string">
<column name="CHAT_LOG_PATH" />
</property>
<property name="roomId" type="java.lang.Integer">
<column name="ROOM_ID" scale="0" />
</property>
<list name="chatAlerts" batch-size="5" cascade="all" lazy="false">
<cache usage="read-only" include="all" />
<key column="ID_CHAT_SESSION" />
<list-index column="ID_USER" />
<one-to-many
class="com.mercer.chat.app.dataobject.MHRContChatAlertsDO" />
</list>
</class>
</hibernate-mapping>
<hibernate-mapping default-lazy="true">
<class name="com.mercer.chat.app.dataobject.MHRContChatAlertsDO" table="QA_TEST3">
<cache usage="read-only" include="all" />
<composite-id >
<key-property name="id" type="java.lang.Long">
<column name="ID_CHAT_SESSION" precision="22" scale="0" />
</key-property>
<key-property name="userId" type="string">
<column name="ID_USER" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>