[jboss-user] [EJB 3.0] - Re: Share entity bean between stateless session beans

2008-11-20 Thread kstrunk
"Rhodan76" wrote : Please check, that you are using the only the 
LOCAL-Interface from the bean as reference

Ah, it works! Thank you very much.

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4191022#4191022

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4191022
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: Share entity bean between stateless session beans

2008-11-20 Thread kstrunk
"Rhodan76" wrote : Please check, that you are using the only the 
LOCAL-Interface from the bean as reference

The local and the remote interfaces are the same interface at the moment. But 
I'll try it with separate interfaces and get back to you.



View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4190815#4190815

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4190815
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: Share entity bean between stateless session beans

2008-11-20 Thread kstrunk
"Wolfgang Knauf" wrote : Hi,
  | 
  | Here is something from chapter 5.6.1, but this does not make it much 
clearer:
  | anonymous wrote : A new persistence context begins when the 
container-managed entity manager is invoked in the scope of an active JTA 
transaction, and there is no current persistence context already associated with
  |   | the JTA transaction. The persistence context is created and then 
associated with the JTA transaction.
  |   | 
  |   | The persistence context ends when the associated JTA transaction 
commits or rolls back, and all entities that were managed by the EntityManager 
become detached.
  |   | 
  |   | If the entity manager is invoked outside the scope of a transaction, 
any entities loaded from the database will immediately become detached at the 
end of the method call.
  | 

Thank you for your quick reply. But I don't understand what's going wrong.

When doSomething of Bean2 is called from an other tier, a new transaction 
should be created. When in doSomething the method findEntity of Bean1 is called 
the same transaction should be used and no new one should be generated, because 
the default transaction type is REQUIRED. So I think that the persistence 
context should be bound to this transaction and the returned entity should not 
get detached, but it's not like this. 

Any ideas why this happens?


View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4190798#4190798

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4190798
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Share entity bean between stateless session beans

2008-11-18 Thread kstrunk
Hi!

I have a problem with two local stateless session beans and an EntityManager 
which is used in one of the SLSBs.

 I want the first SLSB to do basic database operations like finding entities 
and the other one to work with the resulting entities. I attached a small 
example:


@Stateless
public class Bean1 {

@PersistenceContext(unitName = "UnitName")
protected EntityManager entityManager;

public Entity findEntity(...) {
...
}
}


@Stateless
public class Bean2 {

@EJB
private Bean1 bean1;

public User doSomething(...) {
Entity entity = bean1.findEntity();
   
entity.setAnything();
}
}


My problem is that the entity in method doSometing of Bean2 gets detached. So 
any changes of the entity bean (by calling the setter) are not transacted to 
database.

Is this behaviour correct? Is there any way to use a managed entity bean in 
both SLSBs so that I can use the entity in bean2 the same way as in bean1?

Hope someone here can help me!

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4190256#4190256

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4190256
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [Installation, Configuration & Deployment] - Re: log4j configuration in ear file

2007-05-29 Thread kstrunk
Ups, quoting went wrong a little bit in my last posting but hmm, no edit 
button...

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4049472#4049472

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4049472
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [Installation, Configuration & Deployment] - Re: log4j configuration in ear file

2007-05-29 Thread kstrunk
"jwcone" wrote : "kstrunk" wrote : 
  |   | Except for that part about "Using your own log4j.xml file (with EJB JAR 
files )"...
  | 
  | You're right. I found it. Just needed to scroll down a bit more.
  | 
  | I added the ContextRepositorySelector to my ejb.jar and altered it to use 
property files instead of xml files. Now I can log from within my ejb.jar. But 
I cannot log from my WebApp at the same time. 
  | If I put the log4j.jar in my WebApp under WEB-INF/lib logging from WebApp 
works fine, but ejb logging dosen't work. I get no exception or any other error 
message. If I remove log4.jar from my WebApp und put it just in the ear-file 
it's the other way round. I can log from ejb classes but not from the WebApp. 
It looks like a classloading problem, doesn't it?
  | 

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4049470#4049470

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4049470
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [Installation, Configuration & Deployment] - Re: log4j configuration in ear file

2007-05-28 Thread kstrunk
"jwcone" wrote : See the Wiki:
  | http://wiki.jboss.org/wiki/Wiki.jsp?page=ScopedLoggingConfig
  | 

I found this before but the description is for web application only. My WebApp 
is working fine, but I want to get my ejb application to log properly. How can 
I do that?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4049093#4049093

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4049093
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [Installation, Configuration & Deployment] - log4j configuration in ear file

2007-05-27 Thread kstrunk
Hello,

I'm using JBoss 4.2.0 and I want to add a custom log4j.properties to my ejb.jar 
and web.war. I'd like to do the following:

application.ear
| web.war
| ejb.jar
| log4j.jar

I put the log4j.properties in my web.war and in my ejb.jar. Both of them uses 
log4j.jar referenced from MANIFEST. Logging from my WebApp works fine and uses 
the configuration included in web.war. 
Logging from ejb.jar also works, but it doesn't uses the included 
log4j.properties. So what I can I do? Is there any chance to enable custom 
logging in my ejb.jar?

Best regards,
Strunker

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4048920#4048920

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4048920
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [Installation, Configuration & Deployment] - Re: startup error PSQLException

2007-04-09 Thread kstrunk
Hi!

I'm facing the same problem with JBoss 4.0.5 and Postgres 8.2.
Does anybody know what's going wrong?

Strunker

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4035690#4035690

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4035690
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: Entity relationship and remove operations

2007-04-09 Thread kstrunk
"fhh" wrote : Another problem might be that your entityManager is not in sync 
with the database.

You were right. I simply had to refresh the parent and then hibernate could 
delete all references. So it's working now.

Conclusion: Hibernate does the cascading delete itself and does not use 
database features for that.

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4035656#4035656

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4035656
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: Entity relationship and remove operations

2007-04-04 Thread kstrunk
"fhh" wrote : anonymous wrote : 
  |   | And now deleting users works fine, but why is the schema not created 
automatically this way?
  |   | 
  | 
  | I'm not sure whether javax persitence uses the on delete cascade 
functionality of the underlying database or whether the entitymanager will 
"manually" delete ferenced entities.
  | 
  | Regards
  | 
  | Felix

Does anybody here know these details and can me tell what to do now? Manually 
altering the database after deployment cannot be a real solution.

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4034863#4034863

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4034863
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: Entity relationship and remove operations

2007-04-04 Thread kstrunk
Hi!

I've just altered the table to enable cascading:


  | CONSTRAINT fk278c74e4b6f3dc65 FOREIGN KEY (sender)
  |   REFERENCES users (id) MATCH SIMPLE
  |   ON UPDATE NO ACTION ON DELETE CASCADE,
  | 

And now deleting users works fine, but why is the schema not created 
automatically this way?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4034713#4034713

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4034713
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: Entity relationship and remove operations

2007-04-04 Thread kstrunk
"fhh" wrote : Have you looked up which entity the error message refers to and 
to which constraint?
  | 
  | Another problem might be that your entityManager is not in sync with the 
database.
  | 
  | 
  | Regards
  | 
  | Felix

Hi Felix,

the error message refers to member sender of entity ChatMessage. I looked up 
the constraint in my database and there it says:


  | CONSTRAINT fk278c74e4b6f3dc65 FOREIGN KEY (sender)
  |   REFERENCES users (id) MATCH SIMPLE
  |   ON UPDATE NO ACTION ON DELETE NO ACTION,
  | 

I wonder about "ON DELETE NO ACTION". Shouldn't it be "ON DELETE CASCADE"?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4034694#4034694

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4034694
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: Entity relationship and remove operations

2007-04-03 Thread kstrunk
Thanks for your reply.

I tried it out. I removed the name and/or the referencedColumn, but it didn't 
work.

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4034270#4034270

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4034270
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: Entity relationship and remove operations

2007-04-03 Thread kstrunk
Nobody an idea?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4033908#4033908

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4033908
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Re: CMP Entity and foreign keys

2007-04-03 Thread kstrunk
"abhinav19" wrote : 
  | I will check this out in my DB and reply again.
  | 

Have you found out anything?

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4033907#4033907

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4033907
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - CMP Entity and foreign keys

2007-03-20 Thread kstrunk
Hi,

I'm just wondering how JBoss handles foreign key constraints. I have an entity 
with a OneToOne-Mapping and CascaseType.ALL set, but in the database schema no 
cascade delete is set.

Here's a code fragement:


  | @Entity
  | @Table(name = "Users")
  | public class User implements Serializable {
  | private int id;
  | 
  | private ChatInfo chatInfo;
  | 
  | @OneToOne(cascade = {CascadeType.ALL}, fetch = FetchType.EAGER, 
optional = false)
  | public ChatInfo getChatInfo() {
  | return chatInfo;
  | }
  | 
  | public void setChatInfo(ChatInfo chatInfo) {
  | this.chatInfo = chatInfo;
  | }
  | }
  | 
  | @Entity
  | @Table(name = "ChatInfo")
  | public class ChatInfo implements Serializable {
  | private int id;
  | 
  | @Id
  | @GeneratedValue(strategy = GenerationType.IDENTITY)
  | @JoinColumn(name = "id", referencedColumnName = "chatinfo_id", table = 
"users", updatable = false, nullable = false)
  | public int getId() {
  | return id;
  | }
  | 
  | protected void setId(int id) {
  | this.id = id;
  | }
  | 
  | }
  | 

When I look on the database schema there I see "ON DELETE NO ACTION" at the 
foreign key constraint, but I had expected "ON DELETE CASCADE". Can anybode 
explain this?


  | CREATE TABLE users
  | (
  |   id int4 NOT NULL DEFAULT nextval('users_id_seq'::regclass),
  |   chatinfo_id int4 NOT NULL,
  |   CONSTRAINT users_pkey PRIMARY KEY (id),
  |   CONSTRAINT fk4e39de8d7cb3bff FOREIGN KEY (chatinfo_id)
  |   REFERENCES chatinfo (id) MATCH SIMPLE
  |   ON UPDATE NO ACTION ON DELETE NO ACTION,
  | ) 
  | 

I use JBoss 4.0.5 and a Postgres 8.1 database.

Best regards,
Strunker

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4029750#4029750

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4029750
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB 3.0] - Entity relationship and remove operations

2007-03-20 Thread kstrunk
Hello,

I have a problem with entity relationships and foreign key constraints. I want 
to get all child entities deleted when the parent entity is deleted. Therefore 
I used the CasecadeType.REMOVE, but it doesn't work.

Here is code fragment:


  | @Entity
  | @Table(name = "Users")
  | public class User implements Serializable {
  | 
  | private int id;
  | 
  | private List sentChatMessages;
  | private List receivedChatMessages;
  | 
  | @Id
  | @GeneratedValue(strategy = GenerationType.IDENTITY)
  | @Column(name = "id", updatable = false, nullable = false)
  | public int getId() {
  | return id;
  | }
  | 
  | @OneToMany(mappedBy = "sender", cascade = {CascadeType.REMOVE}, fetch = 
FetchType.LAZY)
  | public List getSentChatMessages() {
  | return this.sentChatMessages;
  | }
  | 
  | public void setSentChatMessages(List sentChatMessages) {
  | this.sentChatMessages = sentChatMessages;
  | }
  | 
  | @OneToMany(mappedBy = "receipient", cascade = {CascadeType.REMOVE}, 
fetch = FetchType.LAZY)
  | public List getReceivedChatMessages() {
  | return this.receivedChatMessages;
  | }
  | 
  | public void setReceivedChatMessages(List 
receivedChatMessages) {
  | this.receivedChatMessages = receivedChatMessages;
  | }
  | }
  | 


  | @Entity
  | @Table(name = "ChatMessages")
  | public class ChatMessage implements Serializable {
  | 
  | private User sender;
  | 
  | private User receipient;
  | 
  | private String message;
  | 
  | @ManyToOne()
  | @JoinColumn(name = "sender", referencedColumnName = "id", nullable = 
false)
  | public User getSender() {
  | return this.sender;
  | }
  | 
  | public void setSender(User sender) {
  | this.sender = sender;
  | }
  | 
  | @ManyToOne()
  | @JoinColumn(name = "receipient", referencedColumnName = "id", nullable 
= false)
  | public User getReceipient() {
  | return this.receipient;
  | }
  | 
  | public void setReceipient(User receipient) {
  | this.receipient = receipient;
  | }
  | }
  | 

When I try to delete a user, I exspect that all his messages are also deleted, 
but this does not happen. Instead I get the following exception:

12:12:43,703 ERROR [JDBCExceptionReporter] ERROR: update or delete on "users" 
violates foreign key constraint "fk278c74e4eedef195" on "chatmessages"
  Detail: Key (id)=(12) is still referenced from table "chatmessages".
12:12:43,703 ERROR [AbstractFlushingEventListener] Could not synchronize 
database state with session
org.hibernate.exception.ConstraintViolationException: Could not execute JDBC 
batch update
at 
org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:71)
at 
org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
at 
org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:249)
at 
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:92)
at 
org.hibernate.jdbc.AbstractBatcher.prepareStatement(AbstractBatcher.java:87)
at 
org.hibernate.jdbc.AbstractBatcher.prepareBatchStatement(AbstractBatcher.java:218)
at 
org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2414)
at 
org.hibernate.persister.entity.AbstractEntityPersister.delete(AbstractEntityPersister.java:2632)
at 
org.hibernate.action.EntityDeleteAction.execute(EntityDeleteAction.java:73)
at org.hibernate.engine.ActionQueue.execute(ActionQueue.java:248)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:232)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:144)
at 
org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:298)
at 
org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1000)
at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:338)
at 
org.hibernate.ejb.AbstractEntityManagerImpl$1.beforeCompletion(AbstractEntityManagerImpl.java:515)
at 
org.jboss.tm.TransactionImpl.doBeforeCompletion(TransactionImpl.java:1491)
at org.jboss.tm.TransactionImpl.beforePrepare(TransactionImpl.java:1110)
at org.jboss.tm.TransactionImpl.commit(TransactionImpl.java:324)
at org.jboss.tm.TxManager.commit(TxManager.java:240)
at org.jboss.aspects.tx.TxPolicy.endTransaction(TxPolicy.java:175)
at org.jboss.aspects.tx.TxPolicy.invokeInOurTx(TxPolicy.java:87)
at 
org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:191)
at 
org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
at 
org.jboss.aspects.tx.TxPropagationInterceptor.invoke(Tx

[jboss-user] [EJB/JBoss] - Solved!

2007-02-08 Thread kstrunk
I solved my problem.

The problem was that my Java IDE (idea) started a redeployment automatically 
when I started the JUnits tests. So there were no beans I could access.


View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4013195#4013195

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4013195
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB/JBoss] - Re: Remote not bound

2007-02-06 Thread kstrunk
It is getting strange. When I run my client code (JUnitTest) in debug mode with 
a breakpoint set, everything works fine now. But in normal mode I still get the 
exception:

javax.naming.NameNotFoundException: remote not bound

I really don't understand what's going on. What's different in debug mode? 
Maybe the jar files I need in classpath: Which jars do I need for a remote 
connection with JBoss 4.0.5 and EJB3?

I hope somebody can help me!

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4012090#4012090

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4012090
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [EJB/JBoss] - Re: Remote not bound

2007-02-05 Thread kstrunk
Thank you for your answers, but I still have the same problems.

@jaikiran:
When I do like you've posted, I get the following exception:

javax.naming.NoInitialContextException: Need to specify class name in 
environment or system property, or as an applet parameter, or in an application 
resource file:  java.naming.factory.initial


@ALRubinger
I tried also your suggestion, but I still get the same exception.
My code looks as following now:

@Stateless
@Local(org.community.ejb.business.local.UserManager.class)
@Remote(org.community.ejb.business.remote.UserManager.class)
public class UserManagerBean implements 
org.community.ejb.business.local.UserManager, 
org.community.ejb.business.remote.UserManager {
...
}

@local
public interface UserManager {
...
}

@remote
public interface UserManager {
...
}

Local and remote interfaces are in different packages.

Do you have any more ideas how I can call my bean remote?

Best regards,
Strunker

View the original post : 
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4011549#4011549

Reply to the post : 
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4011549
___
jboss-user mailing list
jboss-user@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/jboss-user


[jboss-user] [Beginners Corner] - UndeclaredThrowableException and duplicate primary key

2006-10-14 Thread kstrunk
Hello!

I'm really new to JBoss and I hope somebody can help me with my first problem I 
can't solve myself.

When I call create on a locale EntityBean with a primary key which already 
exists, I get an UndeclaredThrowableException which is caused by a 
DuplicateKeyException, but I really don't know why this happens. 
The DuplicateKeyException is what I've expected. But why do I get the 
UndeclaredThrowableException?? Does anybody have an idea what I'm doing wrong? 

Here is my code in my test servlet which is running in the bundled tomcat:


  | Properties props = new Properties();
  | 
props.setProperty(Context.INITIAL_CONTEXT_FACTORY,"org.jnp.interfaces.NamingContextFactory");
  | props.setProperty(Context.URL_PKG_PREFIXES,"org.jboss.naming.client");
  | props.setProperty(Context.PROVIDER_URL, "localhost");
  | 
  | InitialContext initialContext = new InitialContext(props);
  | MandatorLocalHome mandatorLocalHome = (MandatorLocalHome) 
initialContext.lookup(MandatorLocalHome.JNDI_NAME);
  | 
  | Integer mandatorId = new Integer(1);
  | try {
  | MandatorLocal mandator = mandatorLocalHome.create(mandatorId);
  | } catch (DuplicateKeyException e) {
  | writer.write("mandator " + mandatorId + " already exists\n");
  | }
  | 

My configuration:
JBoss 4.0.4
PostgreSQL 8.1

And here is the full stacktrace:

  | 16:58:26,500 ERROR [STDERR] java.lang.reflect.UndeclaredThrowableException
  | 16:58:26,500 ERROR [STDERR] at $Proxy166.create(Unknown Source)
  | 16:58:26,531 ERROR [STDERR] at 
org.cryptobox.gui.TestServlet.doPost(TestServlet.java:49)
  | 16:58:26,531 ERROR [STDERR] at 
org.cryptobox.gui.TestServlet.doGet(TestServlet.java:29)
  | 16:58:26,531 ERROR [STDERR] at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
  | 16:58:26,531 ERROR [STDERR] at 
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
  | 16:58:26,531 ERROR [STDERR] at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  | 16:58:26,546 ERROR [STDERR] at 
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
  | 16:58:26,546 ERROR [STDERR] at 
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
  | 16:58:26,546 ERROR [STDERR] at 
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
  | 16:58:26,546 ERROR [STDERR] at 
org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
  | 16:58:26,546 ERROR [STDERR] at java.lang.Thread.run(Thread.java:595)
  | 16:58:26,546 ERROR [STDERR] Caused by: javax.ejb.DuplicateKeyException: 
Entity with primary key 1 already exists
  | 16:58:26,546 ERROR [STDERR] at 
org.jboss.ejb.plugins.cmp.jdbc.JDBCInsertPKCreateCommand.beforeInsert(JDBCInsertPKCreateCommand.java:99)
  | 16:58:26,546 ERROR [STDERR] at 
org.jboss.ejb.plugins.cmp.jdbc.JDBCAbstractCreateCommand.execute(JDBCAbstractCreateCommand.java:150)
  | 16:58:26,546 ERROR [STDERR] at 
org.jboss.ejb.plugins.cmp.jdbc.JDBCStoreManager.createEntity(JDBCStoreManager.java:587)
  | 16:58:26,546 ERROR [STDERR] at 
org.jboss.ejb.plugins.CMPPersistenceManager.createEntity(CMPPersistenceManager.java:237)
  | 16:58:26,546 ERROR [STDERR] at 
org.jboss.resource.connectionmanager.CachedConnectionInterceptor.cr