i using netbeans 7.3.1 , glassfish 4.0. i've created simple maven ejb project. i'm trying delete 1 row table (mysql database). keep getting error:
error occurred during deployment: exception while loading app : javax.ejb.createexception: initialization failed singleton mytester. please see server.log more details. module has not been deployed. see server log details. @ org.netbeans.modules.j2ee.deployment.devmodules.api.deployment.deploy(deployment.java:210) @ org.netbeans.modules.maven.j2ee.executionchecker.performdeploy(executionchecker.java:178) @ org.netbeans.modules.maven.j2ee.executionchecker.executionresult(executionchecker.java:130) @ org.netbeans.modules.maven.execute.mavencommandlineexecutor.run(mavencommandlineexecutor.java:212) @ org.netbeans.core.execution.runclassthread.run(runclassthread.java:153)
session bean:
package com.mycompany.myapp1; import java.io.fileinputstream; import java.io.filenotfoundexception; import java.io.ioexception; import java.util.logging.level; import java.util.logging.logger; import javax.annotation.postconstruct; import javax.ejb.stateless; import javax.ejb.localbean; import javax.ejb.singleton; import javax.ejb.startup; import javax.ejb.stateful; import javax.persistence.entitymanager; import javax.persistence.persistencecontext; import org.apache.commons.io.ioutils; @singleton @localbean @startup public class mytester { @persistencecontext(name="com.mycompany_myapp1_ejb_1.0-snapshotpu") entitymanager em; @postconstruct public void mymain(){ staff staff = em.find(staff.class, 5); system.out.println("deleting..."); em.remove(staff); } }
staff.java:
package com.mycompany.myapp1; import java.io.serializable; import javax.persistence.basic; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.lob; import javax.persistence.namedqueries; import javax.persistence.namedquery; import javax.persistence.table; import javax.validation.constraints.size; @entity public class staff implements serializable { private static final long serialversionuid = 1l; @id @generatedvalue(strategy = generationtype.identity) private integer staffid; private string name; @column(name = "age") private integer age; private string gender; @column(name = "salary") private integer salary; @lob private byte[] pic; public byte[] getpic() { return pic; } public void setpic(byte[] pic) { this.pic = pic; } public staff() { } public staff(integer staffid) { this.staffid = staffid; } public integer getstaffid() { return staffid; } public void setstaffid(integer staffid) { this.staffid = staffid; } public string getname() { return name; } public void setname(string name) { this.name = name; } public integer getage() { return age; } public void setage(integer age) { this.age = age; } public string getgender() { return gender; } public void setgender(string gender) { this.gender = gender; } public integer getsalary() { return salary; } public void setsalary(integer salary) { this.salary = salary; } @override public int hashcode() { int hash = 0; hash += (staffid != null ? staffid.hashcode() : 0); return hash; } @override public boolean equals(object object) { // todo: warning - method won't work in case id fields not set if (!(object instanceof staff)) { return false; } staff other = (staff) object; if ((this.staffid == null && other.staffid != null) || (this.staffid != null && !this.staffid.equals(other.staffid))) { return false; } return true; } @override public string tostring() { return "com.mycompany.myapp1.staff[ staffid=" + staffid + " ]"; } void getgender(string m) { throw new unsupportedoperationexception("not supported yet."); //to change body of generated methods, choose tools | templates. } }
pom:
<?xml version="1.0" encoding="utf-8"?> <project xmlns="http://maven.apache.org/pom/4.0.0" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://maven.apache.org/pom/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelversion>4.0.0</modelversion> <groupid>com.mycompany</groupid> <artifactid>myapp1</artifactid> <version>1.0-snapshot</version> <packaging>ejb</packaging> <name>myapp1</name> <properties> <endorsed.dir>${project.build.directory}/endorsed</endorsed.dir> <project.build.sourceencoding>utf-8</project.build.sourceencoding> </properties> <dependencies> <dependency> <groupid>org.eclipse.persistence</groupid> <artifactid>eclipselink</artifactid> <version>2.5.0-snapshot</version> <scope>provided</scope> </dependency> <dependency> <groupid>org.eclipse.persistence</groupid> <artifactid>javax.persistence</artifactid> <version>2.1.0-snapshot</version> <scope>provided</scope> </dependency> <dependency> <groupid>org.eclipse.persistence</groupid> <artifactid>org.eclipse.persistence.jpa.modelgen.processor</artifactid> <version>2.5.0-snapshot</version> <scope>provided</scope> </dependency> <dependency> <groupid>mysql</groupid> <artifactid>mysql-connector-java</artifactid> <version>5.1.25</version> </dependency> <dependency> <groupid>commons-io</groupid> <artifactid>commons-io</artifactid> <version>1.4</version> </dependency> <dependency> <groupid>javax</groupid> <artifactid>javaee-api</artifactid> <version>7.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-compiler-plugin</artifactid> <version>3.1</version> <configuration> <source>1.7</source> <target>1.7</target> <compilerarguments> <endorseddirs>${endorsed.dir}</endorseddirs> </compilerarguments> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-ejb-plugin</artifactid> <version>2.3</version> <configuration> <ejbversion>3.1</ejbversion> </configuration> </plugin> <plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-dependency-plugin</artifactid> <version>2.6</version> <executions> <execution> <phase>validate</phase> <goals> <goal>copy</goal> </goals> <configuration> <outputdirectory>${endorsed.dir}</outputdirectory> <silent>true</silent> <artifactitems> <artifactitem> <groupid>javax</groupid> <artifactid>javaee-endorsed-api</artifactid> <version>7.0</version> <type>jar</type> </artifactitem> </artifactitems> </configuration> </execution> </executions> </plugin> </plugins> </build> <repositories> <repository> <url>http://download.eclipse.org/rt/eclipselink/maven.repo/</url> <id>eclipselink</id> <layout>default</layout> <name>repository library eclipselink (jpa 2.1)</name> </repository> </repositories> </project>
persistence.xml:
<?xml version="1.0" encoding="utf-8"?> <persistence version="2.1" xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" xsi:schemalocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd"> <persistence-unit name="com.mycompany_myapp1_ejb_1.0-snapshotpu" transaction-type="jta"> <jta-data-source>asas</jta-data-source> <exclude-unlisted-classes>false</exclude-unlisted-classes> <properties/> </persistence-unit> </persistence>
the thing if want add row table example:
public void mymain(){ staff staff = new staff(); staff.setname("john"); staff.setage(22); em.persist(staff); }
i no errors, work fine , see result in database! please help. if change state @singleton @stateless or @stateful there no errors, database not change. going on?
today tried run application again. after clicked run, netbeans starts downloading stuff. , turns out works fine! got 1 warning:
warning: class 'javax.ejb.postactivate' not found, interception based on not enabled
but application deployed , record has been removed table! weird turns out restarting netbeans fixed issue.
Comments
Post a Comment