Please forgive the volume of attached code here. I thought it would
help. I have a container managed Entity bean, pretty simple bean..
manages a mail account on a server.
Rather than call each get/set method to get the properties, I've set
up a getDataMap and storeDataMap which basically just gets and
sets the properties as a batch filling or taking values from a
HashMap. Originally, I didn't want to trigger an update call for each
method so I thought doing them all in one swipe would be better. I
do not believe this is really relevent to the problem, just wanted to
explain the odd bit of code. Also, forgive the hardcoding of a
domain name in there for now. Will switch to properties later.
The rest is pretty standard. The problem is that setDomain gets
called with a new value. The storeRow method gets called. It
prints out that the new value is the correctly modified one. But the
database doesn't seem to get updated. The next read from this
bean has the value back to the old one.
Here are the bean, home, and remote files, along with the data
descriptor and the properties file. I've switched to the isModified
method thinking that maybe a write wasn't being triggered but that
didn't help. I'm going to switch this bean to bean managed I think.
This is the only one that is container managed and the only one
that exhibits this behavior.
If anyone sees a problem here, please let me know. The container
managed beans are far easier to write .. but I need the things to
work. :)
// File MailAccountEJB.java
// EJBean File
package com.nfolink;
import java.sql.*;
import javax.sql.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
public class MailAccountEJB implements EntityBean {
// username CHAR(63) NOT NULL,
// customer integer NOT NULL,
// domain CHAR(127) NOT NULL,
// alias CHAR(255) NOT NULL,
// is_alias ENUM ('yes','no') NOT NULL DEFAULT 'no',
// password CHAR(32) NOT NULL
public String username;
public int customer;
public String domain;
public String alias;
public String is_alias;
public String password;
private EntityContext context;
private transient boolean isDirty;
public boolean isModified() {
return isDirty;
}
public void setModified(boolean flag) {
isDirty = flag;
}
public String getUsername() {
return username;
}
public int getCustomer() {
return customer;
}
public String getDomain() {
return domain;
}
public String getAlias() {
return alias;
}
public String getIsAlias() {
return is_alias;
}
public String getPassword() {
return password;
}
public void setUsername(String u) {
username = u;
setModified(true);
}
public void setDomain(String s) {
domain = s;
setModified(true);
}
public void setAlias(String s) {
alias =s;
setModified(true);
}
public void setIsAlias(String s) {
is_alias = s;
setModified(true);
}
public void setPassword(String s) {
password = s;
setModified(true);
}
public Map getDataMap() {
Map mailMap = new HashMap();
mailMap.put("username", this.username);
mailMap.put("domain", this.domain);
mailMap.put("alias", this.alias);
mailMap.put("is_alias", this.is_alias);
return mailMap;
}
public void storeDataMap(Map mailMap) {
System.out.println("MailAccount: Storing data map");
for (Iterator i = mailMap.keySet().iterator(); i.hasNext(); ) {
String key = (String)i.next();
System.out.println("Updating for key: "+key);
if (key.equals("username")) {
this.setUsername((String)mailMap.get(key));
continue;
}
if (key.equals("password")) {
this.setPassword((String)mailMap.get(key));
continue;
}
if (key.equals("domain")) {
this.setDomain((String)mailMap.get(key));
System.out.println("Domain set to "+domain);
continue;
}
if (key.equals("alias")) {
this.setAlias((String)mailMap.get(key));
continue;
}
if (key.equals("is_alias")) {
this.setIsAlias((String)mailMap.get(key));
continue;
}
}
}
public void ejbCreate(String username, int customer, String
domain,
String alias, String is_alias, String password) {
this.username = username;
this.customer = customer;
if (domain==null || domain.equals(""))
domain = "nfolink.com";
this.domain = domain;
this.alias = alias;
this.is_alias = alias;
this.password = password;
}
public void ejbPostCreate(String username, int customer, String
domain,
String alias, String is_alias, String password) {
}
public void ejbCreate(String username, int customer, String
password) {
this.username = username;
this.customer = customer;
this.domain = "nfolink.com";
this.alias = "";
this.is_alias = "no";
this.password = password;
}
public void ejbPostCreate(String username, int customer, String
password) {
}
public void setEntityContext(EntityContext ctx) {
context = ctx;
setModified(true);
}
public void unsetEntityContext() {
context = null;
}
public void ejbActivate() {
setModified(true);
}
public void ejbPassivate() { }
public void ejbLoad() {
setModified(false);
}
public void ejbStore() {
System.out.println("Completion of stored.");
setModified(false);
}
public void ejbRemove() { }
}
// File MailAccount.java
// Remote Interface
package com.nfolink;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface MailAccount extends EJBObject {
public String getUsername() throws RemoteException;
public int getCustomer() throws RemoteException;
public String getDomain() throws RemoteException;
public String getAlias() throws RemoteException;
public String getIsAlias() throws RemoteException;
public String getPassword() throws RemoteException;
public void setUsername(String u) throws RemoteException;
public void setDomain(String s) throws RemoteException;
public void setAlias(String s) throws RemoteException;
public void setIsAlias(String s) throws RemoteException;
public void setPassword(String s) throws RemoteException;
public java.util.Map getDataMap() throws RemoteException;
public void storeDataMap(java.util.Map mailMap) throws
RemoteException;
}
// File MailAccountHome.java
// Home Interface
package com.nfolink;
import java.util.Collection;
import java.rmi.RemoteException;
import javax.ejb.*;
public interface MailAccountHome extends EJBHome {
public MailAccount create(String username, int customer, String
domain,
String alias, String is_alias, String password)
throws RemoteException, CreateException;
public MailAccount create(String username, int customer, String
password)
throws RemoteException, CreateException;
public MailAccount findByPrimaryKey(MailAccountPK primary)
throws FinderException, RemoteException;
public Collection findByCustomer(int customer)
throws FinderException, RemoteException;
public Collection findAllMailAccounts()
throws FinderException, RemoteException;
}
// File MailAccountDD.txt
// Data Descriptor
EntityDescriptor {
BeanHomeName = "MailAccountHome";
EnterpriseBeanClassName =
com.nfolink.MailAccountEJB;
HomeInterfaceClassName =
com.nfolink.MailAccountHome;
RemoteInterfaceClassName = com.nfolink.MailAccount;
PrimaryKeyClassName =
com.nfolink.MailAccountPK;
EnvironmentProperties = "MailAccount.properties";
ControlDescriptors = {
{
TransactionAttribute = TX_NOT_SUPPORTED;
};
};
ContainerManagedFields = {
username;
customer;
domain;
alias;
is_alias;
password;
};
}
// File MailAccount.properties
// Enviroment properties file
datasource.name jdbc_3
isModifiedMethodName isModified
db.TableName mail_accounts
db.Field.username username
db.Field.customer customer
db.Field.domain domain
db.Field.alias alias
db.Field.is_alias is_alias
db.Field.password password
db.Finder.findByCustomer where customer = ?
db.Finder.findAllMailAccounts
==========================================================================
Timothy Stewart, Lead Developer (Programmer Level IV)
Laureate Inc.
Tel: 512.257.7531 Email: [EMAIL PROTECTED]
Corporate Web page: http://www.laureate.net/
Laureate Inc. specializes in development of distributed evaluation and
assessment systems for educational, governmental, corporate and military
environments.
Our primary focus is the creation of customized, reliable, cross-platform
applications that maintain ease of use and integrate seemlessly into the
instutional enterprise system; we strive in every aspect to avoid the
need to have the institution conform to our software. Rather, our
software conforms to user expectations. Installation is made simple
with the provision of a pre-configured Sun Server and Oracle Database.
For more information, contact [EMAIL PROTECTED]
==========================================================================
----
To unsubscribe, send email to [EMAIL PROTECTED] and
include in the body of the message "unsubscribe jonas-users".
For general help, send email to [EMAIL PROTECTED] and
include in the body of the message "help".