Rene Curth

Greenhorn
+ Follow
since May 13, 2004
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rene Curth

Hi folks,
is there any plan to support JEE5-development with IntelliJ? If not, what about a sole EJB 3.0 assistance, like JBoss Eclipse IDE?

Best regards,
Rene
Hi Jaikiran,
thanks for your (remarkable) quick reaction. This sounds exactly like the answer, I was searching for. I will try this.

Thanks again.

Rene
17 years ago
Hi Mike,
thanks for touching my soul with your wisdom (I'm so unworthy) ;-)
I definitely will change my query, just the old sql habit, you know :-)

No kidding, thanks for analyzing my problem so deeply. I agree with you, that it will be painfull to work around the problem with fake removes, but if hibernate is not willing to do it for me, what choice do I have?

Thanks again.

Rene

p.s. how is it like on top of the oracle pyramid?
Hi Parameswaran,

you definitely need some othe jars in your classpath. To import javax.persistence.* classes, you have to integrate the ejb3-persistence.jar.

If you are using eclipse with JBoss you can use a plugin from JBoss, called JBoss Eclipse IDE 1.6. There are some wizards, which are integrating the nescessary jars for you.

Good luck :-)

Rene
Hi everybody,
I don't know exactly, if this is the right forum, so please don't hang me if it is not.

I do have a problem here.
I have a win 2000 server with some stable running java applications on it. The directive I got from above is: "Never change a winning team".
These applications are using jre 1.4 with a JAVA_HOME environment variable pointing on this jre.
I now have to integrate a JBoss 4.0.4 (EJB 3.0 - important) into this system, which is, so far I know, requiring java 1.5.
I did install a second jre (1.5) - so far so good.

The problem is, to install JBoss properly, that I have to set the JAVA_HOME to the java 1.5 directory. Please remember the above directive, so I can't. The variable has to be remaining unchanged. I think, I'm trapped.

Is it possible to tell JBoss to take the 1.5 version without changing the JAVA_HOME variable?

Any help is highly appreciated. Thanks in advance.

Rene
17 years ago
Hi Mike,
thanks a lot for answering.

I don't know, if I get it completly, but am I right, if I recapitulate your answer like this: the container (JBoss 4.0.4) will check, if a pre-existed object, well, pre-existed and would inform the client about this fact?

I'm not setting version fields by myself and I don't want to persist new objects with existing version numbers.

But I can observe, that a new object will be persisted, if a merge on an unmanaged object will be executed, although the managed version of this object is not existing anymore.

What I would expect, is an exception, if a pre-existed unmanaged POJO, will be merged by the container. Is this correct? If so, how is that be implemented?

I think, this observation is the result of my absence of understanding. So please have a look at my testing code, even if this will violate the "how to ask questions the smart way" rule (if so, sorry for that).


Thanks in advance.

Rene

p.s. I surely will have a look on your book ;-)



package ejbtest;

import java.io.Serializable;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Version;

/**
* represents an entity POJO for demonstrating EJB 3.0 persistance matters
* @author Rene
*
*/
@Entity
public class Depot implements Serializable {

private int id;
private long version;
private String name;

public Depot() {
}

public Depot(String name) {
this.name = name;
}

@Id
@GeneratedValue
public int getId() {
return id;
}

public void setId(int id) {
this.id = id;
}

@Version
protected long getVersion() {
return version;
}

protected void setVersion(long version) {
this.version = version;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}


package ejbtest;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import ejbtest.DepotManager;

public @Stateless class DepotManagerBean implements DepotManager {

@PersistenceContext(unitName = "ejbTest")
private EntityManager manager;

public Depot addDepot(Depot depot) {
manager.persist(depot);
return depot;
}

public void removeDepot(Depot depot) {
manager.remove(depot);
}

public Depot updateDepot(Depot depot) {
return manager.merge(depot);
}

public List getAllDepots() {
Query query = manager.createQuery("from Depot");
return query.getResultList();
}

}


package ejbtest;

import java.util.List;

import javax.ejb.Remote;

@Remote
public interface DepotManager {
public Depot addDepot(Depot depot);
public void removeDepot(Depot depot);
public Depot updateDepot(Depot depot);
public List getAllDepots();
}


package ejbtest;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.List;

import javax.naming.Context;
import javax.naming.NamingException;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.TreeSelectionModel;

/**
* is gui frame, where the user can interact with depot tree,
* to demonstrate entity bean access and currency aspects
* @author Rene
*
*/
public class Client extends JFrame implements ActionListener {

private JPanel buttonPanel;
private JTextField depotName;
private JTree tree;
private JButton addButton, removeButton, renameButton, refreshButton;
private JScrollPane scrollPane;

private Context jndiContext;
private DepotManager manager;

/**
* Client constructor
*
*/
public Client() {
try {
initManager();
initLayout();
} catch (NamingException e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
Client client = new Client();
}

/**
* initialyzes JNDI-Context and references DepotManager
* @throws NamingException
*/
public void initManager() throws NamingException {
jndiContext = getInitialContext();
Object managerBean = jndiContext.lookup("DepotManagerBean/remote");
manager = (DepotManager) managerBean;
}

/**
* initialyzes the GUI-component
*
*/
private void initLayout() {
buttonPanel = new JPanel();
depotName = new JTextField(10);

addButton = createButton("add");
removeButton = createButton("remove");
renameButton = createButton("rename");
refreshButton = createButton("refresh");

buttonPanel.add(depotName);
buttonPanel.add(addButton);
buttonPanel.add(removeButton);
buttonPanel.add(renameButton);
buttonPanel.add(refreshButton);

tree = createTree();
scrollPane = new JScrollPane(tree);

getContentPane().add(scrollPane, BorderLayout.CENTER);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

pack();
setVisible(true);
}

/**
* creates Button
* @param title sets text of button
* @return
*/
private JButton createButton(String title) {
JButton button = new JButton(title);
button.addActionListener(this);

return button;
}

/**
* creates tree of depots
* @return the tree
*/
private JTree createTree() {
List depots = manager.getAllDepots();

DefaultMutableTreeNode top = new DefaultMutableTreeNode("Depots");
Iterator it = depots.iterator();

while (it.hasNext()) {
Depot depot = (Depot) it.next();
DefaultMutableTreeNode node = new DefaultMutableTreeNode(depot);
top.add(node);
}

JTree tree = new JTree(top);
tree.setCellRenderer(new TreeCellRenderer());
tree.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
tree.getSelectionModel().setSelectionMode(
TreeSelectionModel.SINGLE_TREE_SELECTION);

return tree;
}

/**
* refreshes the tree with new data from database
*
*/
private void refreshTree() {
tree = createTree();
scrollPane.setViewportView(tree);
depotName.setText("");
}

/**
* sets the action of the buttons
*/
public void actionPerformed(ActionEvent e) {
/*
* adds new Depot with name from depotName text field,
* sends this depot to application server
* and refreshes the depot tree
*/
if (e.getSource() == addButton) {
if (!depotName.equals("")) {
Depot depot = new Depot(depotName.getText());
depot = manager.addDepot(depot);
refreshTree();
} else {
JOptionPane.showMessageDialog(this,
"Please insert depot name.", "",
JOptionPane.ERROR_MESSAGE);
}

/**
* removes the selected depot
*/
} else if (e.getSource() == removeButton) {
try {
if (tree.getLastSelectedPathComponent() != null) {
Depot depot = (Depot) ((DefaultMutableTreeNode) tree
.getLastSelectedPathComponent()).getUserObject();
manager.removeDepot(depot);
refreshTree();
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Depot was updated. Please refresh view.", "",
JOptionPane.ERROR_MESSAGE);
}

/**
* renames the selected depot with content of depotName text field,
* updates it on application server
*/
} else if (e.getSource() == renameButton) {
try {
if (tree.getLastSelectedPathComponent() != null) {
if (!depotName.getText().equals("")) {
Depot depot = (Depot) ((DefaultMutableTreeNode) tree
.getLastSelectedPathComponent())
.getUserObject();
depot.setName(depotName.getText());
depot = manager.updateDepot(depot);
refreshTree();
} else {
JOptionPane.showMessageDialog(null,
"Please insert depot name.", "",
JOptionPane.ERROR_MESSAGE);
}
}
} catch (Exception ex) {
JOptionPane.showMessageDialog(this,
"Depot was updated. Please refresh view.", "",
JOptionPane.ERROR_MESSAGE);
}
/*
* refreshes depot tree
*/
} else if (e.getSource() == refreshButton) {
refreshTree();
}
}

/**
* gets initial context
* @return context
* @throws javax.naming.NamingException
*/
public Context getInitialContext() throws javax.naming.NamingException {
return new javax.naming.InitialContext();
}

/**
* CellRenderer of depot tree
* @author Rene
*
*/
public class TreeCellRenderer extends DefaultTreeCellRenderer {

/**
* sets text of tree node to name of depot
*/
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row,
boolean hasFocus) {

super.getTreeCellRendererComponent(tree, value, sel, expanded,
leaf, row, hasFocus);

Object o = ((DefaultMutableTreeNode) value).getUserObject();

if (o instanceof Depot) {
Depot depot = (Depot) o;
this.setText(depot.getName());
}

return this;
}
}
}
Hi Parameswaran,
You can now download a test preview on bea: http://commerce.bea.com/showproduct.jsp?family=WLS&major=EJB30Tech&minor=-1&www_WLS-EJB30Tech_Body
which will be integrated in a future version.

I'm using JBoss AS 4.0.4, which is already supporting EJB 3.0.

I can recommend this book: Enterprise JavaBeans 3.0, Fifth Edition, ISBN: 059600978X from o'reilly. It explains a huge range of 3.0 aspects, unfortunately, not the question above.

Rene
Hi Mark,
thanks for answering,

yes I'm using @version. The second POJO (what I think you mean is the POJO of the second client) has the same id as the recently removed entity. In this case no entity with the same id as the client POJO is now existing in the database, so, as the merge will occur, a new entity will be inserted (with a completly new id, that's right), but it is inserted (what a pitty).

Any ideas?

Rene
Hi everybody, I'm clearly new to EJB 3.0, so please be patient with me :-)

I've got some Entity-Beans, which are transferred to a couple of Swing clients. These beans are then existing as POJO's unmanaged on the clients. If one of these clients is removing an entity, a session bean will remove it on the server. The other clients still have the correspondending POJO. If another client will operate on this POJO, e.g. rename its caption, and is then updating it via a session bean (entityManager.merge()), a new entity will be created (standard procedure of merge()).

This is absolutly not, what I want. I'm using optimistic locking, so I expected an Exception, to tell the renaming client, that this entity was removed or updated.

I know, that one have to 'remove' the associated unmanaged POJO's, but I only can think of this on the removing client, not on the others.

I don't want to check every time, when someone is changing a POJO, if this entity was already removed, because I thought, the container would do that for me.

Any ideas? Any help would be highly appreciated.
Thans in advance.

Rene
Hi folks,
I'm not sure, if this is the right place, please forgive me, if it's not.
Anyway, the problem came up, while transfering to JWS.

I'm facing the following:
our application consists of multiple jars and some conf and log files. These files are changed programatically, e.g. by log4j. To use JWS I've to put these outter-jar-files into a jar, right? Okay, done. Finding conf resources seems no problem, but writing into a jar to update logging information by an appender is a tricky one, too much for me. Is anybody out there, who can give me a clue?

Thanks in advance.
Rene
18 years ago
Hi there,
I have to deal with a little problem. In a Combo-Box are displayed a lot of last names, ready for selection. Nearby is an text input field, which is waiting for user entry (also a last name). The javascript function has to detect user action in this input field (e.g. onkeypress) and to update the combobox with names beginning with the characters, displayed in the input field while he (or she) is typing it. The names are stored in a ms sql-server database (more than 7000).
The updating process has to be dynamically. My solution up to this point was to integrate an applet, which contains a swing combo-box. The applet is accessed by an javascript function (onkeypress) and contacts a servlet, doing the sql-job. The servlet returns the result to the applet, which is updating the combo-box. Also it's updating other input text-fields (first name, birthdate) by talking to another javascript function.
I think this solution is very complicated and not very elegant. Is there another way for an javascript function to talk with a server-sided database directly or to put it in other words: is there a way for a javascript function to communicate with a servlet directly?
What about jsp? Is it possible to put jsp-code in a javascript function, doing the job dynamically?
I would appreciate a more elegant way of doing it!
Thanx in advance
Rene