zwwcn

Just another WordPress.com site

Monthly Archives: August 2011

JPA namedquery and mysql

JPA : query specified join fetching, but the owner of the fetched association was not present in the select list

JPA don’t support  right join, we have to use left join and the returned object must be the object after the first from clause.

correct : SELECT a FROM Customer a LEFT JOIN a.address ad…

wrong : SELECT count(ad) FROM Customer a LEFT JOIN a.address ad…

——————————-

native query:

String sqlString = “select count(*) as total from OP_CUSTOMER customer left outer join OP_CUSTOMER_ADDRESS_XREF custAddressType on customer.OBJECT_ID=custAddressType.CUSTOMER_ID left outer join OP_ADDRESSTYPE addressType  on custAddressType.ADDRESS_TYPE_ID=addressType.OBJECT_ID where customer.REC_STATUS=’A’ and addressType.rec_status=’A’ and customer.AGENCY_ID=:agencyId and (addressType.type=’ShipAddress’ or addressType.type=’BillAddress’)”;
Session session = (Session) em.getDelegate();
Query query = (Query)session.createSQLQuery(sqlString)
.setParameter(“agencyId”, currentAgency.getObjID());

Scalar queries

JSF aj4 ajaxsingle=true

When ajaxsingle=true is used in the element then, while ajax submission only that particular element will be submitted instead of whole form.

Example when we have two drop down Country and state. Consider state is mandatory field and state is populated by a4jsupport of country drop down. If we are not making ajaxsingle=true in country drop down then required validation error will be thrown while selecting the country even before user selecting the state.

Boolean vs boolean

java.lang.Boolean value or primitive boolean?

if you use Boolean and get “Property ‘foo’ not readable on type java.lang.Boolean” error in jsf page, change the getter from

public Boolean isEnabled() {}

into

public Boolean getEnabled() {}         (Boolean)

 

primitive boolean should use     public boolean isEnabled() {}

 

duplicate rows with that one-to-many relationship

To avoid duplicate rows with that one-to-many relationship, use a Set.

Code:

Query query = session.createQuery(…);
Set results = new HashSet(query.list());