Hi
I am using HibernateAnnotation 3.2 and JBoss server4.2.
i want to Defining MBeans with Hibernate Annotation. I have created
har file .It contains
jboss-service.xml and
HibernateAnnotation-ds.xml .i have not put any hbm file in my har file.
the servlet which is accesing the mbean is as follows.
Code:
public class Dbconnection extends HttpServlet {
public Dbconnection() {
super();
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
List list = null;
response.setContentType("text/html");
PrintWriter out = response.getWriter();
Session newSession = getSession();
try {
list = newSession.getNamedQuery("implicitSample").list();
CityDetail cityDetail1 ;
for(int i=0;i<list.size();i++){
cityDetail1 = (CityDetail)list.get(i);
System.out.println("City ID :"+cityDetail1.getCityId()+" City Name :"+cityDetail1.getCityName());
}
} catch (Exception e) {
e.printStackTrace();
}
newSession.close();
out.flush();
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}
public Session getSession(){
InitialContext ctx;
Session hsession = null;;
try {
ctx = new InitialContext();
SessionFactory factory = (SessionFactory)ctx.lookup("java:/mbean/prem.HibernateFactory");
System.out.println("factory::"+factory);
hsession = factory.openSession();
} catch (NamingException e) {
e.printStackTrace();
}
return hsession;
}
}
my
jboss-service.xml is as follows
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server>
<!-- Generated file - Do not edit! -->
<server>
<mbean code="org.hibernate.jmx.HibernateService" name="jboss.jca:service=prem.HibernateFactory">
<depends>jboss.jca:service=RARDeployer</depends>
<attribute name="JndiName">java:/mbean/prem.HibernateFactory</attribute>
<attribute name="Datasource">java:/jdbc/prem.SQLServerDS</attribute>
<attribute name="Dialect">org.hibernate.dialect.SQLServerDialect</attribute>
<!-- <attribute name="SessionFactoryName">java:/mbean/prem.AnnotationSessionFactory</attribute> -->
<attribute name="ShowSqlEnabled">true</attribute>
<attribute name="UserTransactionName">UserTransaction</attribute>
<!--
<attribute name="TransactionStrategy">org.hibernate.transaction.JTATransactionFactory</attribute>
<attribute name="TransactionManagerLookupStrategy">org.hibernate.transaction.JBossTransactionManagerLookup</attribute>
-->
</mbean>
</server>
My
HibernateAnnotation-ds.xml is as follows it containd the information about database
Code:
<?xml version="1.0" encoding="UTF-8"?>
<datasources>
<local-tx-datasource>
<jndi-name>jdbc/prem.SQLServerDS</jndi-name>
<connection-url>jdbc:jtds:sqlserver://3.209.5.249:1433/test</connection-url>
<driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
<user-name>test</user-name>
<password>test</password>
<metadata>
<type-mapping>SQLServer</type-mapping>
</metadata>
</local-tx-datasource>
</datasources>
My Bean
CityDetail.javaClass is as follows
Code:
@Entity
@SqlResultSetMapping( name="implict", entities=@EntityResult(entityClass=com.nbsl.CityDetail.class))
@NamedNativeQuery( name="implicitSample", query="select c.CityID CityID, c.CityName CityName from City c", resultSetMapping = "implict")
@Table( name="City" )
public class CityDetail {
@Id
String CityId;
String CityName;
@Column
public String getCityId() {
return CityId;
}
public void setCityId(String cityId) {
CityId = cityId;
}
@Column
public String getCityName() {
return CityName;
}
public void setCityName(String cityName) {
CityName = cityName;
}
}
when i run the servlet i got an error.CityDetail is not mapped.
My problem is it possible to configure Hibernate Annotation with Mbean
and how could i map my annoted class with database without using the hbm file in my har file.
Thank's & Regard's
Omkar