JDBC Multi-Row INSERT peformance is horrible - java

Why would I be getting linear performance on increasing batch sizes for this Spring JDBC implementation. Is there some further tuning I might do (apart from an explain, indice review, and database settings tuning)? I should mention I am running this code against a MySQL 5.6 instance hosted on an AWS db.r3.2xlarge class RDS server.
#Repository
public class JdbcRatePlanLevelCostPriceLogRepository implements Insertable<RatePlanLevelCostPriceLog> {
#Autowired
JdbcTemplate jdbcTemplate;
private static final String INSERT_STATEMENT = InsertStatementBuilder.build();
#Override
public RatePlanLevelCostPriceLog insert(RatePlanLevelCostPriceLog entity) {
jdbcTemplate.execute(INSERT_STATEMENT, new SingleCallbackImpl(entity));
return entity;
}
#Override
public List<RatePlanLevelCostPriceLog> insert(List<RatePlanLevelCostPriceLog> entities) {
jdbcTemplate.batchUpdate(INSERT_STATEMENT, new BatchPreparedStatementSetter() {
#Override
public void setValues(PreparedStatement ps, int i) throws SQLException {
RatePlanLevelCostPriceLog entity = entities.get(i);
PreparedStatementTranslator.translate(ps, entity);
}
#Override
public int getBatchSize() {
return entities.size();
}
});
return entities;
}
private static class InsertStatementBuilder {
static String build() {
StringBuffer colsBuffer = new StringBuffer();
StringBuffer valuesBuffer = new StringBuffer();
colsBuffer.append("INSERT INTO rate_plan_level_cost_price_log(");
valuesBuffer.append("VALUES (");
// handle the #NotNull fields
colsBuffer.append("hotel_id");
colsBuffer.append(",rate_plan_id");
colsBuffer.append(",stay_date");
colsBuffer.append(",rate_plan_level");
colsBuffer.append(",person_count");
colsBuffer.append(",length_of_stay_in_days");
colsBuffer.append(",rpcp_log_seq_num");
colsBuffer.append(",log_action_type_id");
colsBuffer.append(",active_status_type_id");
colsBuffer.append(",supplier_update_date");
colsBuffer.append(",create_date");
colsBuffer.append(",supplier_update_tpid");
colsBuffer.append(",supplier_update_tuid");
colsBuffer.append(",supplier_log_seq_num");
// handle the optional fields
colsBuffer.append(",cost_amount");
colsBuffer.append(",cost_code");
colsBuffer.append(",price_amount");
colsBuffer.append(",change_request_id");
colsBuffer.append(",change_request_id_old");
colsBuffer.append(",lar_amount");
colsBuffer.append(",lar_margin_amount");
colsBuffer.append(",lar_taxes_and_fees_amount");
valuesBuffer.append("?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?");
colsBuffer.append(")");
valuesBuffer.append(")");
return String.join(" ", colsBuffer.toString(), valuesBuffer.toString());
}
}
private static class PreparedStatementTranslator {
static void translate(PreparedStatement ps, RatePlanLevelCostPriceLog entity) throws SQLException {
int i = 0;
// handle the #NotNull fields
ps.setInt(++i, entity.getHotelId());
ps.setInt(++i, entity.getRatePlanId());
ps.setTimestamp(++i, new Timestamp(entity.getStayDate().getTime()));
ps.setInt(++i, entity.getRatePlanLevel());
ps.setInt(++i, entity.getPersonCount());
ps.setInt(++i, entity.getLengthOfStayInDays());
ps.setInt(++i, entity.getRpcpLogSeqNum());
ps.setInt(++i, entity.getLogActionTypeId());
ps.setInt(++i, entity.getActiveStatusTypeId());
ps.setTimestamp(++i, new Timestamp(entity.getSupplierUpdateDate().getTime()));
ps.setTimestamp(++i, new Timestamp(entity.getCreateDate().getTime()));
ps.setInt(++i, entity.getSupplierUpdateTpid());
ps.setInt(++i, entity.getSupplierUpdateTuid());
ps.setInt(++i, entity.getSupplierLogSeqNum());
// handle the optional fields
if (entity.getCostAmount() != null) {
ps.setDouble(++i, entity.getCostAmount());
} else {
ps.setNull(++i, Types.DOUBLE);
}
if (entity.getCostCode() != null) {
ps.setString(++i, entity.getCostCode());
} else {
ps.setNull(++i, Types.VARCHAR);
}
if (entity.getPriceAmount() != null) {
ps.setDouble(++i, entity.getPriceAmount());
} else {
ps.setNull(++i, Types.DOUBLE);
}
if (entity.getChangeRequestId() != null) {
ps.setInt(++i, entity.getChangeRequestId());
} else {
ps.setNull(++i, Types.INTEGER);
}
if (entity.getChangeRequestIdOld() != null) {
ps.setInt(++i, entity.getChangeRequestIdOld());
} else {
ps.setNull(++i, Types.INTEGER);
}
if (entity.getLarAmount() != null) {
ps.setDouble(++i, entity.getLarAmount());
} else {
ps.setNull(++i, Types.DOUBLE);
}
if (entity.getLarMarginAmount() != null) {
ps.setDouble(++i, entity.getLarMarginAmount());
} else {
ps.setNull(++i, Types.DOUBLE);
}
if (entity.getLarTaxesAndFeesAmount() != null) {
ps.setDouble(++i, entity.getLarTaxesAndFeesAmount());
} else {
ps.setNull(++i, Types.DOUBLE);
}
}
}
private class SingleCallbackImpl implements PreparedStatementCallback<Boolean> {
private final RatePlanLevelCostPriceLog entity;
SingleCallbackImpl(RatePlanLevelCostPriceLog entity) {
this.entity = entity;
}
#Override
public Boolean doInPreparedStatement(PreparedStatement ps) throws SQLException,
DataAccessException {
PreparedStatementTranslator.translate(ps, entity);
return ps.execute();
}
}
}
It takes ~250 ms to execute a single record insert and then N * 250 ms for batches of N.

Related

How to use an object that got return in another class

I have this class, that returns an object, if the email, password and category (enum) are correct:
public class LoginManager {
private static LoginManager instance = new LoginManager();
private LoginManager() {
super();
}
public static LoginManager getInstance() {
return instance;
}
public ClientFacade login(String email, String password, ClientType clientType) throws SQLException {
if (clientType == ClientType.Administrator) {
AdminFacade adminFacade = new AdminFacade();
if (adminFacade.login(email, password) == true) {
return adminFacade;
} else {
return null;
}
} else if (clientType == ClientType.Company) {
CompanyFacade companyFacade = new CompanyFacade();
if (companyFacade.login(email, password) == true) {
return companyFacade;
} else {
return null;
}
} else if (clientType == ClientType.Customer) {
CustomerFacade customerFacade = new CustomerFacade();
if (customerFacade.login(email, password) == true) {
return customerFacade;
} else {
return null;
}
} else {
return null;
}
}
}
How do I use that object in another class?
This is the other class, that is supposed to use the object that return:
public class Test {
CouponsDBDAO coupDBD = new CouponsDBDAO();
CouponExpirationDailyJob dailyJob =
new CouponExpirationDailyJob(coupDBD, false);
LoginManager Log = LoginManager.getInstance();
public void testAll() {
try {
Log.login("admin#admin.com", "admin", ClientType.Administrator); {
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}
}
How do I use now the adminFacade for example?
try
LoginManager Log = new LoginManager();
public void testAll() {
try {
ClientFacade facade = Log.login("admin#admin.com", "admin", ClientType.Administrator);
facade.DoSomethingUseful();
} catch (SQLException e) {
System.out.println(e.getMessage());
}
}

Spring boot Active Directory/LDAP connection

I already connect with AD from spring boot for login purposes but i can not mak searches. My configuration is
#Configuration
public class LdapTemplateConfig {
#Bean
public LdapTemplate ldapTemplate() {
LdapTemplate ldapTemplate = new LdapTemplate(ldapContextSource());
return ldapTemplate;
}
#Bean
public LdapContextSource ldapContextSource() {
String url = "ldap://127.0.0.1:389";
String base = "DC=demo1,DC=demo2,DC=demo3,DC=demo4";
LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setUrl(url);
ldapContextSource.setUserDn(
"CN=User Name,OU=Common Users OU,OU=RDP enabled Users OU,OU=Operator Users OU,OU=Admin Users OU,DC=demo1,DC=demo2,DC=demo3,DC=demo4");
ldapContextSource.setPassword("password");
// ldapContextSource.setReferral("follow");
ldapContextSource.afterPropertiesSet();
return ldapContextSource;
}
}
#Service
public class LDAPServiceImpl {
#Autowired
private LdapTemplate ldapTemplate;
public void getUserDetails(String userName) {
if (null != ldapTemplate) {
List<String> vals = ldapTemplate.search(query().where("objectclass").is("person"),
new AttributesMapper<String>() {
#Override
public String mapFromAttributes(Attributes attributes) throws NamingException {
return attributes.get("sAMAccountName").get().toString();
}
});
for (String s : vals) {
log.info("attr : " + s);
}
} else {
log.info("Templates is null");
}
}
}
So, when i call the function getUserDetails() from controller it returns "Templates is null"
Spring dependency injection can be done via constructor or setter.
#Autowired
private LdapTemplate ldapTemplate;
Your LDAPServiceImpl class does not have constructor taking LdapTemplate as an argument & the ldapTemplate is declared as private. So constructor injection & setter injection both are not possible. To use setter injection, there needs to be a setter method for ldapTemplate like this:
public void setLdapTemplate(LdapTemplate ldapTemplate){
this.ldapTemplate=ldapTemplate;
}
I solved the problem thanks all for your help
#Configuration
public class LdapTemplateConfig {
private final Logger log = LoggerFactory.getLogger(LdapTemplateConfig.class);
#Bean(name = "ldapTemplate")
// #Scope("singleton")
public LdapTemplate ldapTemplate(LdapContextSource contextSource) {
LdapTemplate ldapTemplate = new LdapTemplate(contextSource);
return ldapTemplate;
}
#Bean(name = "contextSource")
// #Scope("singleton")
public LdapContextSource ldapContextSource() {
String url = "ldap://127.0.0.1:389";
String base = "DC=intranet,DC=demo,DC=com";
if (isConfigurationValid(url, base)) {
LdapContextSource ldapContextSource = new LdapContextSource();
ldapContextSource.setUrl(url);
ldapContextSource.setBase(base);
ldapContextSource.setUserDn(
"CN=Test User,OU=Common Users OU,OU=RDP enabled Users OU,DC=intranet,DC=demo,DC=com");
ldapContextSource.setPassword("password");
ldapContextSource.setReferral("follow");
// lcs.setPooled(false);
// lcs.setDirObjectFactory(DefaultDirObjectFactory.class);
ldapContextSource.afterPropertiesSet();
return ldapContextSource;
}
return null;
}
public boolean isConfigurationValid(String url, String base) {
if ((url == null) || url.isEmpty() || (base == null) || base.isEmpty()) {
log.error("Warning! Your LDAP server is not configured.");
log.info("Did you configure your LDAP settings in your application.yml?");
return false;
} else {
return true;
}
}
}
#Service
public class LDAPServiceImpl {
private final Logger log = LoggerFactory.getLogger(LDAPServiceImpl.class);
#Autowired
LdapTemplate ldapTemplate;
public User getUserDetails(String userName) {
AndFilter filter = new AndFilter();
filter.and(new EqualsFilter("objectclass", "person")).and(new EqualsFilter("employeeID", "700335"));
List<User> users = ldapTemplate.search("", filter.encode(), new UaserAttributesMapper());
if (!users.isEmpty()) {
return users.get(0);
}
return null;
// List<User> list =
// ldapTemplate.search(query().where("sAMAccountName").is("a.keskempes"),
// new UserAttributesMapper());
// if ((list != null) && !list.isEmpty()) {
// return list.get(0);
// }
// return null;
}
private class UaserAttributesMapper implements AttributesMapper<User> {
#Override
public User mapFromAttributes(Attributes attributes) throws NamingException {
User user;
if (attributes == null) {
return null;
}
user = new User();
if (attributes.get("objectclass") != null) {
user.setObjectclass(attributes.get("objectclass").get().toString());
}
if (attributes.get("distinguishedname") != null) {
user.setDistinguishedname(attributes.get("distinguishedname").get().toString());
}
if (attributes.get("userPassword") != null) {
user.setUserPassword(attributes.get("userPassword").get().toString());
}
if (attributes.get("cn") != null) {
user.setCn(attributes.get("cn").get().toString());
}
if (attributes.get("telephoneNumber") != null) {
user.setTelephoneNumber(attributes.get("telephoneNumber").get().toString());
}
// if (attributes.get("lastlogoff") != null) {
// // user.setLastlogoff(DateTimeFormat.forPattern("yyyy-MM-dd
// // HH:mm:ss")
// //
// .parseDateTime(attributes.get("lastlogoff").get().toString()));
// DateTimeFormatter formatter =
// DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss");
// DateTime dt =
// formatter.parseDateTime(attributes.get("lastlogoff").get().toString());
// user.setLastlogoff(new DateTime(
//
// dt
//
// ));
// }
if (attributes.get("userprincipalname") != null) {
user.setUserprincipalname(attributes.get("userprincipalname").get().toString());
}
if (attributes.get("department") != null) {
user.setDepartment(attributes.get("department").get().toString());
}
if (attributes.get("company") != null) {
user.setCompany(attributes.get("company").get().toString());
}
if (attributes.get("mail") != null) {
user.setMail(attributes.get("mail").get().toString());
}
if (attributes.get("streetAddress") != null) {
user.setStreetAddress(attributes.get("streetAddress").get().toString());
}
if (attributes.get("st") != null) {
user.setSt(attributes.get("st").get().toString());
}
if (attributes.get("postalCode") != null) {
user.setPostalCode(attributes.get("postalCode").get().toString());
}
if (attributes.get("l") != null) {
user.setL(attributes.get("l").get().toString());
}
if (attributes.get("description") != null) {
user.setDescription(attributes.get("description").get().toString());
}
if (attributes.get("c") != null) {
user.setC(attributes.get("c").get().toString());
}
if (attributes.get("countryCode") != null) {
user.setCountryCode(attributes.get("countryCode").get().toString());
}
if (attributes.get("cn") != null) {
user.setCn(attributes.get("cn").get().toString());
}
if (attributes.get("sn") != null) {
user.setSn(attributes.get("sn").get().toString());
}
if (attributes.get("employeeID") != null) {
user.setEmployeeId(attributes.get("employeeID").get().toString());
}
if (attributes.get("lastLogon") != null) {
// user.setLastLogon(DateTimeFormat.forPattern("yyyy-MM-dd
// HH:mm:ss")/*
// .parseDateTime(attributes.get("lastLogon").get().toString()));*/
DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss");
DateTime dt = formatter.parseDateTime(attributes.get("lastLogon").get().toString());
user.setLastLogon(new DateTime(
dt
));
}
if (attributes.get("memberof") != null) {
user.setMemberof(attributes.get("memberof").get().toString());
}
if (attributes.get("givenname") != null) {
user.setGivenname(attributes.get("givenname").get().toString());
}
if (attributes.get("logoncount") != null) {
user.setLogoncount(attributes.get("logoncount").get().toString());
}
if (attributes.get("displayName") != null) {
user.setDisplayname(attributes.get("displayName").get().toString());
}
return user;
}
}
}
and into the controller i put
#Autowired
private LDAPServiceImpl lDAPServiceImpl;
com.ppc.ptol2.service.impl.User find = lDAPServiceImpl.getUserDetails("sgad");
as you can see the solution is working perfectly but needds some improvements

Could not find java.beans.propertydescriptor on android

my app uses another projects which contains references to classes as java.beans.propertydescriptor which is not contained by android libraries.
The situation is the next: my project contains the .jar files with this another projects as libraries. I read that the solution is use an opensource class. I found it, but i dont know how can i add this class to the android .jar file. So, how can i add this class to the android java.beans library?
This is the class i have found:
package java.beans;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Vector;
import org.apache.harmony.beans.internal.nls.Messages;
public class PropertyDescriptor extends FeatureDescriptor {
private Method getter;
private Method setter;
private Class<?> propertyEditorClass;
private boolean constrained;
private boolean bound;
public PropertyDescriptor(String propertyName, Class<?> beanClass,
String getterName, String setterName) throws IntrospectionException {
super();
if (beanClass == null) {
throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
}
if (propertyName == null || propertyName.length() == 0) {
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
}
this.setName(propertyName);
this.setDisplayName(propertyName);
if (setterName != null) {
if (hasMethod(beanClass, setterName)) {
setWriteMethod(beanClass, setterName);
} else {
throw new IntrospectionException(Messages.getString("beans.20")); //$NON-NLS-1$
}
}
if (getterName != null) {
if (hasMethod(beanClass, getterName)) {
setReadMethod(beanClass, getterName);
} else {
throw new IntrospectionException(Messages.getString("beans.1F")); //$NON-NLS-1$
}
}
}
public PropertyDescriptor(String propertyName, Method getter, Method setter)
throws IntrospectionException {
super();
if (propertyName == null || propertyName.length() == 0) {
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
}
this.setName(propertyName);
this.setDisplayName(propertyName);
setWriteMethod(setter);
setReadMethod(getter);
}
public PropertyDescriptor(String propertyName, Class<?> beanClass)
throws IntrospectionException {
String getterName;
String setterName;
if (beanClass == null) {
throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
}
if (propertyName == null || propertyName.length() == 0) {
throw new IntrospectionException(Messages.getString("beans.04")); //$NON-NLS-1$
}
this.setName(propertyName);
this.setDisplayName(propertyName);
getterName = createDefaultMethodName(propertyName, "is"); //$NON-NLS-1$
if (hasMethod(beanClass, getterName)) {
setReadMethod(beanClass, getterName);
} else {
getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
if (hasMethod(beanClass, getterName)) {
setReadMethod(beanClass, getterName);
}
}
setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
if (hasMethod(beanClass, setterName)) {
setWriteMethod(beanClass, setterName);
}
if (getter == null && setter == null) {
throw new IntrospectionException(Messages.getString(
"beans.01", propertyName)); //$NON-NLS-1$
}
}
public void setWriteMethod(Method setter) throws IntrospectionException {
if (setter != null) {
int modifiers = setter.getModifiers();
if (!Modifier.isPublic(modifiers)) {
throw new IntrospectionException(Messages.getString("beans.05")); //$NON-NLS-1$
}
Class<?>[] parameterTypes = setter.getParameterTypes();
if (parameterTypes.length != 1) {
throw new IntrospectionException(Messages.getString("beans.06")); //$NON-NLS-1$
}
Class<?> parameterType = parameterTypes[0];
Class<?> propertyType = getPropertyType();
if (propertyType != null && !propertyType.equals(parameterType)) {
throw new IntrospectionException(Messages.getString("beans.07")); //$NON-NLS-1$
}
}
this.setter = setter;
}
public void setReadMethod(Method getter) throws IntrospectionException {
if (getter != null) {
int modifiers = getter.getModifiers();
if (!Modifier.isPublic(modifiers)) {
throw new IntrospectionException(Messages.getString("beans.0A")); //$NON-NLS-1$
}
Class<?>[] parameterTypes = getter.getParameterTypes();
if (parameterTypes.length != 0) {
throw new IntrospectionException(Messages.getString("beans.08")); //$NON-NLS-1$
}
Class<?> returnType = getter.getReturnType();
if (returnType.equals(Void.TYPE)) {
throw new IntrospectionException(Messages.getString("beans.33")); //$NON-NLS-1$
}
Class<?> propertyType = getPropertyType();
if ((propertyType != null) && !returnType.equals(propertyType)) {
throw new IntrospectionException(Messages.getString("beans.09")); //$NON-NLS-1$
}
}
this.getter = getter;
}
public Method getWriteMethod() {
return setter;
}
public Method getReadMethod() {
return getter;
}
#Override
public boolean equals(Object object) {
boolean result = (object != null && object instanceof PropertyDescriptor);
if (result) {
PropertyDescriptor pd = (PropertyDescriptor) object;
boolean gettersAreEqual = (this.getter == null)
&& (pd.getReadMethod() == null) || (this.getter != null)
&& (this.getter.equals(pd.getReadMethod()));
boolean settersAreEqual = (this.setter == null)
&& (pd.getWriteMethod() == null) || (this.setter != null)
&& (this.setter.equals(pd.getWriteMethod()));
boolean propertyTypesAreEqual = this.getPropertyType() == pd
.getPropertyType();
boolean propertyEditorClassesAreEqual = this
.getPropertyEditorClass() == pd.getPropertyEditorClass();
boolean boundPropertyAreEqual = this.isBound() == pd.isBound();
boolean constrainedPropertyAreEqual = this.isConstrained() == pd
.isConstrained();
result = gettersAreEqual && settersAreEqual
&& propertyTypesAreEqual && propertyEditorClassesAreEqual
&& boundPropertyAreEqual && constrainedPropertyAreEqual;
}
return result;
}
public void setPropertyEditorClass(Class<?> propertyEditorClass) {
this.propertyEditorClass = propertyEditorClass;
}
public Class<?> getPropertyType() {
Class<?> result = null;
if (getter != null) {
result = getter.getReturnType();
} else if (setter != null) {
Class<?>[] parameterTypes = setter.getParameterTypes();
result = parameterTypes[0];
}
return result;
}
public Class<?> getPropertyEditorClass() {
return propertyEditorClass;
}
public void setConstrained(boolean constrained) {
this.constrained = constrained;
}
public void setBound(boolean bound) {
this.bound = bound;
}
public boolean isConstrained() {
return constrained;
}
public boolean isBound() {
return bound;
}
boolean hasMethod(Class<?> beanClass, String methodName) {
Method[] methods = findMethods(beanClass, methodName);
return (methods.length > 0);
}
String createDefaultMethodName(String propertyName, String prefix) {
String result = null;
if (propertyName != null) {
String bos = propertyName.substring(0, 1).toUpperCase();
String eos = propertyName.substring(1, propertyName.length());
result = prefix + bos + eos;
}
return result;
}
Method[] findMethods(Class<?> aClass, String methodName) {
Method[] allMethods = aClass.getMethods();
Vector<Method> matchedMethods = new Vector<Method>();
Method[] result;
for (Method method : allMethods) {
if (method.getName().equals(methodName)) {
matchedMethods.add(method);
}
}
result = new Method[matchedMethods.size()];
for (int j = 0; j < matchedMethods.size(); ++j) {
result[j] = matchedMethods.elementAt(j);
}
return result;
}
void setReadMethod(Class<?> beanClass, String getterName) {
boolean result = false;
Method[] getters = findMethods(beanClass, getterName);
for (Method element : getters) {
try {
setReadMethod(element);
result = true;
} catch (IntrospectionException ie) {
}
if (result) {
break;
}
}
}
void setWriteMethod(Class<?> beanClass, String setterName)
throws IntrospectionException {
boolean result = false;
Method[] setters = findMethods(beanClass, setterName);
for (Method element : setters) {
try {
setWriteMethod(element);
result = true;
} catch (IntrospectionException ie) {
}
if (result) {
break;
}
}
}
public PropertyEditor createPropertyEditor(Object bean) {
PropertyEditor editor;
if (propertyEditorClass == null) {
return null;
}
if (!PropertyEditor.class.isAssignableFrom(propertyEditorClass)) {
// beans.48=Property editor is not assignable from the
// PropertyEditor interface
throw new ClassCastException(Messages.getString("beans.48")); //$NON-NLS-1$
}
try {
Constructor<?> constr;
try {
// try to look for the constructor with single Object argument
constr = propertyEditorClass.getConstructor(Object.class);
editor = (PropertyEditor) constr.newInstance(bean);
} catch (NoSuchMethodException e) {
// try no-argument constructor
constr = propertyEditorClass.getConstructor();
editor = (PropertyEditor) constr.newInstance();
}
} catch (Exception e) {
// beans.47=Unable to instantiate property editor
RuntimeException re = new RuntimeException(
Messages.getString("beans.47"), e); //$NON-NLS-1$
throw re;
}
return editor;
}
}
Thanks.
I downloaded from this page https://code.google.com/p/openbeans/downloads/detail?name=openbeans-1.0.jar the openbean.jar. Then, i imported this jar to the project and changed the references at imported library.
Then export again the project as .jar library and import in the android project.

How to make hibernate not to update XMLType column after query

When I use hibernate to query a ORM mapping object, It always update the object to database immediately.I've check this problem, and find it was caused by a mapping property 'appliedTestConfig'. When I remove this property from mapping file,The query operation is only query operation.
Anybody can give me some help?
The follow is a part of the mapping file.
<hibernate-mapping default-lazy="false">
<class name="cs.bean.CSBucket" table="CS_BUCKET" schema="DB2ADMIN">
<id name="bucketId" type="java.lang.Long">
<column name="BUCKET_ID" />
<generator class="native" />
</id>
<property name="bucketName" type="java.lang.String">
<column name="BUCKET_NAME" />
</property>
<property name="appliedTestConfig" type="cs.bean.AppliedTestConfig">
<column name="APPLIED_TEST_CONFIG" />
</property>
</class>
</hibernate-mapping>
The following is a part of CSBucket.java.
public class CSBucket implements java.io.Serializable {
// Fields
private Long bucketId;
private String bucketName;
private AppliedTestConfig appliedTestConfig;
public CSBucket(){
}
public Long getBucketId() {
return bucketId;
}
public void setBucketId(Long bucketId) {
this.bucketId = bucketId;
}
public String getBucketName() {
return bucketName;
}
public void setBucketName(String bucketName) {
this.bucketName = bucketName;
}
public AppliedTestConfig getAppliedTestConfig() {
return appliedTestConfig;
}
public void setAppliedTestConfig(AppliedTestConfig appliedTestConfig) {
this.appliedTestConfig = appliedTestConfig;
}
}
The following is apart of AppliedTestConfig.java file.It is extends UserXMLType.
public class AppliedTestConfig extends UserXMLType {
private static final long serialVersionUID = 1L;
private List<String> jccDrivers = new ArrayList<String>();
private List<DB2Server> db2Servers = new ArrayList<DB2Server>();
public Serializable disassemble(Object value) throws HibernateException {
if ((value instanceof AppliedTestConfig) && value != null) {
// System.out.println("into the applied");
List<DB2Server> db2List = ((AppliedTestConfig) value)
.getDb2Servers();
List<String> jccList = ((AppliedTestConfig) value).getJccDrivers();
StringBuffer strBuf = new StringBuffer();
strBuf = strBuf.append("<applied_test_config>");
if (null != db2List && db2List.size() > 0) {
strBuf = strBuf.append("<db2server_cofig>");
for (int i = 0; i < db2List.size(); i++) {
strBuf = strBuf.append("<db2server>");
// strBuf.append(list.get(i));
DB2Server db2server = (DB2Server) db2List.get(i);
strBuf.append("<os>");
strBuf.append(db2server.getOs());
strBuf.append("</os>");
strBuf.append("<version>");
strBuf.append(db2server.getVersion());
strBuf.append("</version>");
strBuf.append("<dbcs>");
if ("".equals(db2server.getDbcs())
|| null == db2server.getDbcs()) {
strBuf.append("NULL");
} else {
strBuf.append(db2server.getDbcs());
}
strBuf.append("</dbcs>");
strBuf = strBuf.append("</db2server>");
}
strBuf = strBuf.append("</db2server_cofig>");
}
if (null != jccList && jccList.size() > 0) {
strBuf = strBuf.append("<jccdriver_config>");
for (int i = 0; i < jccList.size(); i++) {
strBuf = strBuf.append("<jccdriver>");
strBuf = strBuf.append((String) jccList.get(i));
strBuf = strBuf.append("</jccdriver>");
}
strBuf = strBuf.append("</jccdriver_config>");
}
strBuf = strBuf.append("</applied_test_config>");
return strBuf.toString();
} else
return null;
}
public Object assemble(Serializable cached, Object owner)
throws HibernateException {
jccDrivers = new ArrayList<String>();
db2Servers = new ArrayList<DB2Server>();
if (cached != null) {
String strVal = (String) cached;
Document doc = XMLTool.loadDocumentFromStr(strVal);
if (doc != null) {
Node db2Node = XMLTool.getSingleNode(doc, "db2server_cofig");
NodeList db2NodeList = null;
if (db2Node != null) {
db2NodeList = XMLTool.getMultiNodes(db2Node, "db2server");
} else {
// Do nothing
}
Node jccNode = XMLTool.getSingleNode(doc, "jccdriver_config");
NodeList jccNodeList = null;
if (jccNode != null) {
jccNodeList = XMLTool.getMultiNodes(jccNode, "jccdriver");
} else {
// Do nothing
}
if (jccNodeList != null) {
for (int i = 0, n = jccNodeList.getLength(); i < n; i++) {
if (jccNodeList.item(i) instanceof Node) {
Node subNode = jccNodeList.item(i);
String nodeValue = XMLTool.getNodeValue(subNode);
if (nodeValue != null
&& !"".equals(nodeValue.trim())) {
jccDrivers.add(nodeValue);
}
}
}
}
// set db2Server
if (db2NodeList != null) {
for (int i = 0, n = db2NodeList.getLength(); i < n; i++) {
if (db2NodeList.item(i) instanceof Node) {
Node osNode = XMLTool.getSingleNode(db2NodeList
.item(i), "os");
Node versionNode = XMLTool.getSingleNode(
db2NodeList.item(i), "version");
Node dbcsNode = XMLTool.getSingleNode(db2NodeList
.item(i), "dbcs");
String osValue = XMLTool.getNodeValue(osNode);
String versionValue = XMLTool
.getNodeValue(versionNode);
String dbcsValue = XMLTool.getNodeValue(dbcsNode);
DB2Server db2server = new DB2Server(osValue,
versionValue, dbcsValue);
db2Servers.add(db2server);
}
}
}
}
}
AppliedTestConfig one = new AppliedTestConfig();
one.setDb2Servers(db2Servers);
one.setJccDrivers(jccDrivers);
return one;
}
public boolean equals(Object x, Object y) throws HibernateException {
if (x == y)
return true;
if (x != null && y != null) {
// todo: to modify this to detail equal
return x.equals(y);
}
return false;
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result
+ ((db2Servers == null) ? 0 : db2Servers.hashCode());
result = prime * result
+ ((jccDrivers == null) ? 0 : jccDrivers.hashCode());
return result;
}
#Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AppliedTestConfig other = (AppliedTestConfig) obj;
if (db2Servers == null) {
if (other.db2Servers != null)
return false;
} else if (!db2Servers.equals(other.db2Servers))
return false;
if (jccDrivers == null) {
if (other.jccDrivers != null)
return false;
} else if (!jccDrivers.equals(other.jccDrivers))
return false;
return true;
}
/**
* Generate Getters and Setters....
* */
}
The following is UserXMLType file
public abstract class UserXMLType implements UserType, Serializable {
private static final long serialVersionUID = 1L;
private static final int[] TYPES = new int[] { Types.VARCHAR };
public int[] sqlTypes() {
return TYPES;
}
public Class returnedClass() {
// TODO Auto-generated method stub
System.out.println("===>>>return Class is : " + this.getClass());
return this.getClass();
}
public abstract boolean equals(Object first, Object second) throws HibernateException ;
public Object nullSafeGet(ResultSet rs, String[] names, Object owner) throws HibernateException, SQLException {
System.out.println("===>>>nullSafeGet is executed.");
String value = (String) Hibernate.STRING.nullSafeGet(rs, names[0]);
if (value != null) {
return assemble(value,owner);
} else {
return null;
}
}
public void nullSafeSet(PreparedStatement st, Object value, int index) throws HibernateException, SQLException {
System.out.println("===>>>nullSafeSet is executed.");
if (value != null) {
Serializable str =disassemble(value);
Hibernate.STRING.nullSafeSet(st, str, index);
} else {
Hibernate.STRING.nullSafeSet(st, value, index);
}
}
public Object deepCopy(Object value) throws HibernateException {
System.out.println("===>>>deepCopy is executed.");
Object result=null;
// dingk *
//if (value==null) return "";
if (value==null) return null;
if (!(value instanceof Serializable)) {
throw new HibernateException("Clone锟侥讹拷锟斤拷锟斤拷锟绞碉拷锟絡ava.io.Serializable锟接口o拷");
}
ByteArrayOutputStream bo = new ByteArrayOutputStream();
ObjectOutputStream oo = null;
ObjectInputStream oi = null;
try {
oo = new ObjectOutputStream(bo);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
oo.writeObject(value);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ByteArrayInputStream bi = new ByteArrayInputStream(bo.toByteArray());
try {
oi = new ObjectInputStream(bi);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
result = oi.readObject();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
public boolean isMutable() {
return false;
}
public int hashCode(Object arg0) throws HibernateException {
// TODO Auto-generated method stub
return arg0.hashCode();
}
public abstract Serializable disassemble(Object obj) throws HibernateException ;
public abstract Object assemble(Serializable value, Object owner) throws HibernateException;
public Object replace(Object arg0, Object arg1, Object arg2) throws HibernateException {
if (arg0==null) return null;
if(this.isMutable()){
return deepCopy(arg0);
}
else{
return arg0;
}
}
}
The following is the console output when i query a CSBucket.
[13-5-16 15:32:50:109 CST] 00000022 SystemOut O Hibernate:
select
csbucket0_.BUCKET_ID as BUCKET1_57_,
csbucket0_.BUCKET_NAME as BUCKET2_57_,
csbucket0_.LOC_IN_CMVC as LOC3_57_,
csbucket0_.OWNER as OWNER57_,
csbucket0_.ORIGINATOR as ORIGINATOR57_,
csbucket0_.IS_MANUAL as IS6_57_,
csbucket0_.BUCKET_TYPE as BUCKET7_57_,
csbucket0_.RUN_TYPE as RUN8_57_,
csbucket0_.CUSTOMIZE as CUSTOMIZE57_,
csbucket0_.ONLINE_CHECK as ONLINE10_57_,
csbucket0_.LINE_ITEM_DCR as LINE11_57_,
csbucket0_.STORE_UDFS_LOC as STORE12_57_,
csbucket0_.BUCKET_CLASS as BUCKET13_57_,
csbucket0_.DESCRIPTION as DESCRIP14_57_,
csbucket0_.DB_LUW as DB15_57_,
csbucket0_.DB_ZOS as DB16_57_,
csbucket0_.JCLS_NEEDED as JCLS17_57_,
csbucket0_.INPUT_FILE_LOC as INPUT18_57_,
csbucket0_.UTLITITES as UTLITITES57_,
csbucket0_.TEST_FOCUS as TEST20_57_,
csbucket0_.TC_NO as TC21_57_,
csbucket0_.MAIN_FUNCTION as MAIN22_57_,
csbucket0_.MAX_TIME as MAX23_57_,
csbucket0_.OTHER_INSTRUCT as OTHER24_57_,
csbucket0_.ACTIVE_STATUS as ACTIVE25_57_,
csbucket0_.CREATOR as CREATOR57_,
csbucket0_.UPDATOR as UPDATOR57_,
csbucket0_.ACTIVATOR as ACTIVATOR57_,
csbucket0_.PRE_BUCKET_ID as PRE29_57_,
csbucket0_.CERTAIN_JCC as CERTAIN30_57_,
csbucket0_.APPLIED_RELEASE as APPLIED31_57_,
csbucket0_.APPLIED_TEST_CONFIG as APPLIED32_57_,
csbucket0_.APPLIED_JDK as APPLIED33_57_,
csbucket0_.TXT_PARM as TXT34_57_,
csbucket0_.BUCKET_RUN as BUCKET35_57_,
csbucket0_.BUCKET_FILE as BUCKET36_57_
from
DB2ADMIN.CS_BUCKET csbucket0_
where
csbucket0_.BUCKET_NAME like '%xml_index_aps_qad_j01%'
[13-5-16 15:32:52:250 CST] 00000022 SystemOut O ===>>>nullSafeGet is executed.
[13-5-16 15:32:52:640 CST] 00000022 SystemOut O ===>>>deepCopy is executed.
[13-5-16 15:32:52:828 CST] 00000022 SystemOut O Hibernate:
update
DB2ADMIN.CS_BUCKET
set
BUCKET_NAME=?,
LOC_IN_CMVC=?,
OWNER=?,
ORIGINATOR=?,
IS_MANUAL=?,
BUCKET_TYPE=?,
RUN_TYPE=?,
CUSTOMIZE=?,
ONLINE_CHECK=?,
LINE_ITEM_DCR=?,
STORE_UDFS_LOC=?,
BUCKET_CLASS=?,
DESCRIPTION=?,
DB_LUW=?,
DB_ZOS=?,
JCLS_NEEDED=?,
INPUT_FILE_LOC=?,
UTLITITES=?,
TEST_FOCUS=?,
TC_NO=?,
MAIN_FUNCTION=?,
MAX_TIME=?,
OTHER_INSTRUCT=?,
ACTIVE_STATUS=?,
CREATOR=?,
UPDATOR=?,
ACTIVATOR=?,
PRE_BUCKET_ID=?,
CERTAIN_JCC=?,
APPLIED_RELEASE=?,
APPLIED_TEST_CONFIG=?,
APPLIED_JDK=?,
TXT_PARM=?,
BUCKET_RUN=?,
BUCKET_FILE=?
where
BUCKET_ID=?
[13-5-16 15:32:52:953 CST] 00000022 SystemOut O ===>>>nullSafeSet is executed.
[13-5-16 15:32:53:171 CST] 00000022 SystemOut O ===>>>deepCopy is executed.
Now,anybody can help me to make a query operation not to update database ? Thanks very much.

Null pointer exception using weblogic 10g bean injection jpa/ejb

I have a problem with my EJB / JPA project. I use netbeans, weblogic 10g and Java EE app.
My problem is, I create "Entity classes from database" and after that I create "session beans for entity classes" which are basically my facades.
Then I go over my war project and say "JSF pages for entity classses" Netbeans creates all the classes nicely.
At the beginning it says I have to have a persistence provider and for that aim I add the library "Hibernate JPA".
Here is my ArchJpaController:
package JPAControllerS;
import JPAControllerS.exceptions.NonexistentEntityException;
import JPAControllerS.exceptions.RollbackFailureException;
import entities.Arch;
import java.io.Serializable;
import java.util.List;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityNotFoundException;
import javax.persistence.Query;
import javax.transaction.UserTransaction;
public class ArchJpaController implements Serializable {
public ArchJpaController(UserTransaction utx, EntityManagerFactory emf) {
this.utx = utx;
this.emf = emf;
}
private UserTransaction utx = null;
private EntityManagerFactory emf;
public EntityManager getEntityManager() {
return emf.createEntityManager();
}
public void create(Arch arch) throws RollbackFailureException, Exception {
EntityManager em = null;
try {
utx.begin();
em = getEntityManager();
em.persist(arch);
utx.commit();
} catch (Exception ex) {
try {
utx.rollback();
} catch (Exception re) {
throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
}
throw ex;
} finally {
if (em != null) {
em.close();
}
}
}
public void edit(Arch arch) throws NonexistentEntityException, RollbackFailureException, Exception {
EntityManager em = null;
try {
utx.begin();
em = getEntityManager();
arch = em.merge(arch);
utx.commit();
} catch (Exception ex) {
try {
utx.rollback();
} catch (Exception re) {
throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
}
String msg = ex.getLocalizedMessage();
if (msg == null || msg.length() == 0) {
Integer id = arch.getId();
if (findArch(id) == null) {
throw new NonexistentEntityException("The arch with id " + id + " no longer exists.");
}
}
throw ex;
} finally {
if (em != null) {
em.close();
}
}
}
public void destroy(Integer id) throws NonexistentEntityException, RollbackFailureException, Exception {
EntityManager em = null;
try {
utx.begin();
em = getEntityManager();
Arch arch;
try {
arch = em.getReference(Arch.class, id);
arch.getId();
} catch (EntityNotFoundException enfe) {
throw new NonexistentEntityException("The arch with id " + id + " no longer exists.", enfe);
}
em.remove(arch);
utx.commit();
} catch (Exception ex) {
try {
utx.rollback();
} catch (Exception re) {
throw new RollbackFailureException("An error occurred attempting to roll back the transaction.", re);
}
throw ex;
} finally {
if (em != null) {
em.close();
}
}
}
public List<Arch> findArchEntities() {
return findArchEntities(true, -1, -1);
}
public List<Arch> findArchEntities(int maxResults, int firstResult) {
return findArchEntities(false, maxResults, firstResult);
}
private List<Arch> findArchEntities(boolean all, int maxResults, int firstResult) {
EntityManager em = getEntityManager();
try {
Query q = em.createQuery("select object(o) from Arch as o");
if (!all) {
q.setMaxResults(maxResults);
q.setFirstResult(firstResult);
}
return q.getResultList();
} finally {
em.close();
}
}
public Arch findArch(Integer id) {
EntityManager em = getEntityManager();
try {
return em.find(Arch.class, id);
} finally {
em.close();
}
}
public int getArchCount() {
EntityManager em = getEntityManager();
try {
Query q = em.createQuery("select count(o) from Arch as o");
return ((Long) q.getSingleResult()).intValue();
} finally {
em.close();
}
}
}
And here is my ArchController:
package JSFClasses;
import entities.Arch;
import JSFClasses.util.JsfUtil;
import JSFClasses.util.PaginationHelper;
import JPAControllerS.ArchJpaController;
import java.io.Serializable;
import java.util.ResourceBundle;
import javax.annotation.Resource;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.SelectItem;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.transaction.UserTransaction;
#ManagedBean(name = "archController")
#SessionScoped
public class ArchController implements Serializable {
#Resource
private UserTransaction utx = null;
#PersistenceUnit(unitName = "IBB_Latest-warPU")
private EntityManagerFactory emf = null;
private Arch current;
private DataModel items = null;
private ArchJpaController jpaController = null;
private PaginationHelper pagination;
private int selectedItemIndex;
public ArchController() {
}
public Arch getSelected() {
if (current == null) {
current = new Arch();
selectedItemIndex = -1;
}
return current;
}
private ArchJpaController getJpaController() {
if (jpaController == null) {
jpaController = new ArchJpaController(utx, emf);
}
return jpaController;
}
public PaginationHelper getPagination() {
if (pagination == null) {
pagination = new PaginationHelper(10) {
#Override
public int getItemsCount() {
return getJpaController().getArchCount();
}
#Override
public DataModel createPageDataModel() {
return new ListDataModel(getJpaController().findArchEntities(getPageSize(), getPageFirstItem()));
}
};
}
return pagination;
}
public String prepareList() {
recreateModel();
return "List";
}
public String prepareView() {
current = (Arch) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
return "View";
}
public String prepareCreate() {
current = new Arch();
selectedItemIndex = -1;
return "Create";
}
public String create() {
try {
getJpaController().create(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("ArchCreated"));
return prepareCreate();
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
public String prepareEdit() {
current = (Arch) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
return "Edit";
}
public String update() {
try {
getJpaController().edit(current);
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("ArchUpdated"));
return "View";
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
return null;
}
}
public String destroy() {
current = (Arch) getItems().getRowData();
selectedItemIndex = pagination.getPageFirstItem() + getItems().getRowIndex();
performDestroy();
recreatePagination();
recreateModel();
return "List";
}
public String destroyAndView() {
performDestroy();
recreateModel();
updateCurrentItem();
if (selectedItemIndex >= 0) {
return "View";
} else {
// all items were removed - go back to list
recreateModel();
return "List";
}
}
private void performDestroy() {
try {
getJpaController().destroy(current.getId());
JsfUtil.addSuccessMessage(ResourceBundle.getBundle("/Bundle").getString("ArchDeleted"));
} catch (Exception e) {
JsfUtil.addErrorMessage(e, ResourceBundle.getBundle("/Bundle").getString("PersistenceErrorOccured"));
}
}
private void updateCurrentItem() {
int count = getJpaController().getArchCount();
if (selectedItemIndex >= count) {
// selected index cannot be bigger than number of items:
selectedItemIndex = count - 1;
// go to previous page if last page disappeared:
if (pagination.getPageFirstItem() >= count) {
pagination.previousPage();
}
}
if (selectedItemIndex >= 0) {
current = getJpaController().findArchEntities(1, selectedItemIndex).get(0);
}
}
public DataModel getItems() {
if (items == null) {
items = getPagination().createPageDataModel();
}
return items;
}
private void recreateModel() {
items = null;
}
private void recreatePagination() {
pagination = null;
}
public String next() {
getPagination().nextPage();
recreateModel();
return "List";
}
public String previous() {
getPagination().previousPage();
recreateModel();
return "List";
}
public SelectItem[] getItemsAvailableSelectMany() {
return JsfUtil.getSelectItems(getJpaController().findArchEntities(), false);
}
public SelectItem[] getItemsAvailableSelectOne() {
return JsfUtil.getSelectItems(getJpaController().findArchEntities(), true);
}
#FacesConverter(forClass = Arch.class)
public static class ArchControllerConverter implements Converter {
public Object getAsObject(FacesContext facesContext, UIComponent component, String value) {
if (value == null || value.length() == 0) {
return null;
}
ArchController controller = (ArchController) facesContext.getApplication().getELResolver().
getValue(facesContext.getELContext(), null, "archController");
return controller.getJpaController().findArch(getKey(value));
}
java.lang.Integer getKey(String value) {
java.lang.Integer key;
key = Integer.valueOf(value);
return key;
}
String getStringKey(java.lang.Integer value) {
StringBuffer sb = new StringBuffer();
sb.append(value);
return sb.toString();
}
public String getAsString(FacesContext facesContext, UIComponent component, Object object) {
if (object == null) {
return null;
}
if (object instanceof Arch) {
Arch o = (Arch) object;
return getStringKey(o.getId());
} else {
throw new IllegalArgumentException("object " + object + " is of type " + object.getClass().getName() + "; expected type: " + Arch.class.getName());
}
}
}
}
Finally my exception:
java.lang.NullPointerException
at JPAControllerS.ArchJpaController.getEntityManager(ArchJpaController.java:43)
at JPAControllerS.ArchJpaController.findArchEntities(ArchJpaController.java:132)
at JPAControllerS.ArchJpaController.findArchEntities(ArchJpaController.java:128)
at JSFClasses.ArchController$1.createPageDataModel(ArchController.java:66)
at JSFClasses.ArchController.getItems(ArchController.java:166)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at javax.el.BeanELResolver.getValue(BeanELResolver.java:261)
at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
at com.sun.el.parser.AstValue.getValue(AstValue.java:118)
at com.sun.el.parser.AstEqual.getValue(AstEqual.java:41)
at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:192)
at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109)
at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194)
at javax.faces.component.UIComponentBase.isRendered(UIComponentBase.java:413)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1750)
at javax.faces.render.Renderer.encodeChildren(Renderer.java:168)
at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1756)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1759)
at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:401)
at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:134)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:410)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:292)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:43)
at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:43)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3496)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(Unknown Source)
at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2180)
at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2086)
at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1406)
at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
If someone could help me on this issue I would be greatly appreciated.
first: What version of JPA are you using? 1.0 or 2.0? If you use 2.0, weblogic by default doesn't support it.
But you can enable making following changes:
locate the file commEnv.cmd(or sh for linux). The file is in WEBLOGIC_HOME/common/bin. Example for windows: C:\Oracle\Middleware\wlserver_10.3\common\bin
Add the following lines to the file
#rem JAR AGREGADOS PARA EL SOPORTE DE JPA2.0 EN WLS
set PRE_CLASSPATH=%MW_HOME%/modules/javax.persistence_1.0.0.0_2-0-0.jar;%MW_HOME%/modules/com.oracle.jpa2support_1.0.0.0_2-0.jar
restart de weblogic server
For inject the persitent unit you can use
#PersistenceContext(unitName = "PersistenceUnitName")
private EntityManager em;
On your facade or dao clasess
You don't need an EntityManagerFactory injection.
I hope this help you.
Sorry for my english... It`s really bad .. :-(

Categories