Hi,
Is there a reason you're using a native query for this, and not a
JPAQL query?
What you get from a native query is data, not objects. Your code is
looking for an Account object and should use a JPAQL query.
Craig
On Jan 11, 2010, at 11:06 AM, racarlson wrote:
public class Database
{
//
*******************************************************************************************
private final static Logger LOG =
Logger.getLogger( Database.class ) ;
//log4j
private static EntityManagerFactory entityManagerFactory ;
private static final String JPA_FACTORY_NAME = "MyJpaFactory";
//
*******************************************************************************************
private void closeEntityManager (
final EntityManager em )
{
try
{
if ( ( em != null ) &&
( em.isOpen( ) ) )
{
em.close( ) ;
}
}
catch ( final Exception e )
{
Database.LOG.error( e ) ;
}
}
//
*******************************************************************************************
private void setupEntityManagerFactory ( )
{
if ( Database.entityManagerFactory == null )
{
Database.entityManagerFactory =
Persistence.createEntityManagerFactory( Database.JPA_FACTORY_NAME ) ;
}
}
//
*******************************************************************************************
private EntityManager getEntityManager ( )
{
this.setupEntityManagerFactory( ) ;
final EntityManager entityManager =
Database.entityManagerFactory.createEntityManager( ) ;
entityManager.getTransaction( ).begin( );
return entityManager ;
}
//
*******************************************************************************************
private EntityManager getEntityManagerWithOutTransaction ( )
{
this.setupEntityManagerFactory( ) ;
return Database.entityManagerFactory.createEntityManager( ) ;
}
//
*******************************************************************************************
private void logQuery (
final String temp )
{
if ( temp != null )
{
Database.LOG.debug( temp ) ;
}
}
//
*******************************************************************************************
public Account getAccountByBillingSystemAccountNumber (
final String billingSystemAccountNumber )
{
final EntityManager em =
this.getEntityManagerWithOutTransaction( ) ;
return this.getAccountByBillingSystemAccountNumber(
billingSystemAccountNumber ,
em ,
true ) ;
}
//
*******************************************************************************************
protected Account getAccountByBillingSystemAccountNumber (
final String billingSystemAccountNumber ,
final EntityManager em ,
final boolean canCloseEntityManager )
{
Account rtn = null ;
try
{
final String sql =
"select * from ACCOUNT a "+
"where
a.BILLING_SYSTEM_ACCOUNT_NUMBER = \'" +
billingSystemAccountNumber + "\' " ;
final Query q = em.createNativeQuery( sql ,
Account.class ) ;
this.logQuery( sql ) ;
if ( q != null )
{
rtn = ( Account ) q.getResultList( ).get( 0 );
}
}
catch ( final NoResultException nre )
{
rtn = null ;
}
finally
{
if ( canCloseEntityManager )
{
this.closeEntityManager( em ) ;
}
}
return rtn ;
}
//
*******************************************************************************************
/* some other methods to access other tables
.......
*/
}
--
View this message in context:
http://n2.nabble.com/openjpa-ignoring-column-annotation-tp4286639p4287474.html
Sent from the OpenJPA Users mailing list archive at Nabble.com.
Craig L Russell
Architect, Sun Java Enterprise System http://db.apache.org/jdo
408 276-5638 mailto:[email protected]
P.S. A good JDO? O, Gasp!