According to my own question i just found another problem with data initialization during PostConstruct in Startup Singleton. The problem is caused by primary key violation, which is generated during:
@Singleton
@Startup
public class DefaultDataIntializer {
@PostConstruct
public void init()
{
BlinkUser bu = createDefaultUser();
BlinkGroup bg = createDefaultGroup();
Link l = createDefaultLink();
UserLink ul = createDefaultUserLink();
if(buf.find(bu.getEmail()) != null)
return;
bg.addUser(bu);
ul.setLink(l);
ul.setOwner(bu);
lf.create(l);
bgf.create(bg);
buf.create(bu);
ulf.create(ul);
}
}
And here is full deployment's log. Problem is in:
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry 'user@gmail.com' for key 'PRIMARY'
But when i am using debugger that problem is not showing up during creation. Maybe is caused by some cache? Well, that's long shot, i just didn't find anything wrong especially i check existing of example data before creation (DefaultDataInitializer::init():5). Also, it's my persistence.xml:
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
<persistence-unit name="BlinkLinkServer-ejbPU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<jta-data-source>java:jboss/datasources/BlinkLinkDataSource</jta-data-source>
<exclude-unlisted-classes>false</exclude-unlisted-classes>
<properties>
<property name="hibernate.hbm2ddl.auto" value="create"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
</properties>
</persistence-unit>
Maybe it's something wrong with some transaction? I shouldn't initialize data that way? Thanks for help!
Edit: Root cause is duplicated invoking postConstruct method. Even synchronized or additional variable (even static) isn't solving problem. Even debugger isn't showing second invoke (isn't stopping on breakpoint second time). So how i figured it out this is different methods?
public synchronized void init()
{
Logger.getAnonymousLogger().warning("Initializing data!" + (new Random()).nextInt());
//rest of previous code
}
Which gives:
16:08:21,079 WARNING [null] (ServerService Thread Pool -- 424) Initializing data!778044534
16:08:21,116 WARNING [null] (ServerService Thread Pool -- 423) Initializing data!1060447455