[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Newsgroup Home]
|
[news.eclipse.rt.eclipselink] Fixed String or Oracle CHAR
|
- From: nic@xxxxxxxxxxxx (Nick)
- Date: Wed, 9 Jul 2008 14:59:55 +0000 (UTC)
- Newsgroups: eclipse.rt.eclipselink
- Organization: Eclipse
- User-agent: NewsPortal/0.36 (http://florian-amrhein.de/newsportal)
I'm in the process of porting an application from Toplink Essentials to
eclipselink because we need some of the new features or extension of
eclipselink, but we encounter a snag...
All things considered, setup and etc, a SessionCustomizer that looks like
below that will handle CHAR columns doesn't work on eclipselink anymore?
Or am I missing something?
Thanks,
Nick
public class OracleSessionCustomizer implements SessionCustomizer {
public void customize(Session session) {
session.getEventManager().addListener(new OracleSessionListener());
//set the default for the columns.
session.getLogin().setDefaultNullValue(String.class, " ");
session.getLogin().setDefaultNullValue(Integer.class, 0);
session.getLogin().setDefaultNullValue(Long.class, 0);
}
class OracleSessionListener extends SessionEventAdapter {
@Override
public void postAcquireConnection(SessionEvent event) {
Connection conn = ((DatabaseAccessor) event.getResult()).getConnection();
OracleConnection oconn = (OracleConnection) conn;
oconn.setDefaultFixedString(true);
}
}
}
The same SessionCustomizer will work in Toplink flawlessly, where the PK's
are CHAR's:
For example using find:
pk.setCol1("XYZ");
pk.setCol2(" "); <--- a single space
EntityA entity = em.find(EntityA.class, pk);
For example using persist:
EntityB entity = new EntityB();
entity.setCol1("XYZ");
entity.setCol2(null);
em.getTransaction().begin();
em.find(entity);
em.getTransaction().commit();
eclipselink will not insert spaces but instead nulls