Fixed String or Oracle CHAR [message #376325] |
Wed, 09 July 2008 14:59 |
Nick Messages: 34 Registered: July 2009 |
Member |
|
|
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
|
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.02062 seconds