This is the
UserAFinderImpl class in this class I have declared 1 method. i.e findUser()
this method takes no argument and gives the result in the form of list object.
package
com.adrsuser.slayer.service.persistence;
import
java.util.ArrayList;
import java.util.List;
import
javax.portlet.ActionRequest;
import
com.adrsuser.slayer.model.AddressU;
import
com.adrsuser.slayer.model.UserA;
import
com.adrsuser.slayer.model.impl.AddressUImpl;
import
com.adrsuser.slayer.model.impl.UserAImpl;
import
com.liferay.portal.kernel.dao.orm.SQLQuery;
import
com.liferay.portal.kernel.dao.orm.Session;
import
com.liferay.portal.kernel.exception.SystemException;
import
com.liferay.portal.service.persistence.impl.BasePersistenceImpl;
import
com.liferay.util.dao.orm.CustomSQLUtil;
public class UserAFinderImpl
extends BasePersistenceImpl
implements UserAFinder{
public static String FIND_USERS = "findUsers";
public List
findUser() throws SystemException
{
Session
session = null;
try
{
List objectListUserAddress=new ArrayList();
List objectListUser=new ArrayList();
List objectList=new ArrayList();
session
= openSession();
String sql = CustomSQLUtil.get(FIND_USERS);
System.out.println("Query -----"+sql);
SQLQuery query = session.createSQLQuery(sql);
query.addEntity("UserA", UserAImpl.class);
objectListUser=(List)query.list();
objectList.add(objectListUser);
session=openSession();
query
= session.createSQLQuery(sql);
query.addEntity("AddressU", AddressUImpl.class);
objectListUserAddress=(List)query.list();
objectList.add(objectListUserAddress);
return (List)objectList;
}
catch (Exception e) {
System.out.println(e);
}
return null;
}
}
In My jsp page I have written simply like this…
<%@page import="java.util.ArrayList"%>
<%@page import="com.adrsuser.slayer.model.UserA"%>
<%@page import="com.adrsuser.slayer.model.AddressU"%>
<%@page import="java.util.List"%>
<%@page import="com.adrsuser.slayer.service.UserALocalServiceUtil"%>
<h1>success fully
reached....</h1>
<%
List objectListUser=new ArrayList();
List objectList=new ArrayList();
objectList=UserALocalServiceUtil.findUser();
List<UserA> h1=(List)objectList.get(0);
List<AddressU> h2=(List)objectList.get(1);
for(UserA ha:h1)
{
%>
<%=ha.getUaid() %>
<%=ha.getUid()%>
<%=ha.getUname()%>
<% }
for(AddressU hb:h2)
{
%>
<%=hb.getCity()%>
<%=hb.getState()%>
<%=hb.getCountry()%>
<%
}
%>
This is my service.xml here are 2 tables UserA and AddressU.
<?xml version="1.0"
encoding="UTF-8"?>
<!DOCTYPE service-builder
PUBLIC "-//Liferay//DTD
Service Builder 6.0.0//EN" "http://www.liferay.com/dtd/liferay-service-builder_6_0_0.dtd">
<service-builder package-path="com.adrsuser.slayer">
<author>sudheer</author>
<namespace>AU</namespace>
<entity name="UserA"
local-service="true" remote-service="true">
<!-- PK
fields -->
<column name="uid"
type="int" primary="true"
/>
<!-- Audit
fields -->
<column name="uname"
type="String" />
<column name="uaid"
type="int" />
</entity>
<entity name="AddressU"
local-service="true" remote-service="true">
<!-- PK
fields -->
<column name="uaid"
type="int" primary="true"
/>
<!-- Audit
fields -->
<column name="country"
type="String" />
<column name="state"
type="String" />
<column name="city"
type="String" />
</entity>
</service-builder>
MYSQL QUERY is
ReplyDeleteselect * from au_usera as t1
inner join au_addressu as t2 on t1.uaid=t2.uaid;