我有一个关于JBOSS的问题。我设计了一个名为Login.jsp的jsp页面。当我运行它时,它在开始时正常工作。但是当我添加会话bean和实体时,我收到的错误如下:
21:28:53,762 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 48) HHH000389: Unsuccessful: drop table order if exists
21:28:53,763 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 48) Syntax error in SQL statement "DROP TABLE ORDER[*] IF EXISTS "; expected "identifier"; SQL statement:
drop table order if exists [42001-168]
21:28:53,763 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 48) HHH000389: Unsuccessful: drop sequence hibernate_sequence
21:28:53,763 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 48) Sequence "HIBERNATE_SEQUENCE" not found; SQL statement:
drop sequence hibernate_sequence [90036-168]
21:28:53,766 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 48) HHH000389: Unsuccessful: create table order (O_ID integer not null, B_ID integer, C_ID integer, QUANTITY integer not null, primary key (O_ID))
21:28:53,766 ERROR [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 48) Syntax error in SQL statement "CREATE TABLE ORDER[*] (O_ID INTEGER NOT NULL, B_ID INTEGER, C_ID INTEGER, QUANTITY INTEGER NOT NULL, PRIMARY KEY (O_ID)) "; expected "identifier"; SQL statement:
create table order (O_ID integer not null, B_ID integer, C_ID integer, QUANTITY integer not null, primary key (O_ID)) [42001-168]
21:28:53,771 INFO [org.hibernate.tool.hbm2ddl.SchemaExport] (ServerService Thread Pool -- 48) HHH000230: Schema export complete
21:28:54,471 ERROR [org.jboss.msc.service.fail] (MSC service thread 1-3) MSC000001: Failed to start service jboss.deployment.unit."jboss-as-greeter.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."jboss-as-greeter.war".WeldStartService: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1767) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) [rt.jar:1.6.0_22]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) [rt.jar:1.6.0_22]
at java.lang.Thread.run(Unknown Source) [rt.jar:1.6.0_22]
Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Unsatisfied dependencies for type [EntityManagerFactory] with qualifiers [@Default] at injection point [[field] @Inject protected org.jboss.as.quickstarts.greeter.domain.SessionBean.emf]
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:311)
at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:280)
at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:143)
at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:163)
at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:382)
at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:367)
at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:379)
at org.jboss.as.weld.WeldStartService.start(WeldStartService.java:64)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.4.GA-redhat-1.jar:1.0.4.GA-redhat-1]
... 3 more
21:28:54,767 INFO [org.jboss.as.server] (ServerService Thread Pool -- 26) JBAS018559: Deployed "jboss-as-greeter.war" (runtime-name : "jboss-as-greeter.war")
21:28:54,774 INFO [org.jboss.as.controller] (Controller Boot Thread) JBAS014774: Service status report
JBAS014777: Services which failed to start: service jboss.deployment.unit."jboss-as-greeter.war".WeldStartService: org.jboss.msc.service.StartException in service jboss.deployment.unit."jboss-as-greeter.war".WeldStartService: Failed to start service
21:28:54,854 ERROR [org.jboss.as] (Controller Boot Thread) JBAS015875: JBoss EAP 6.1.0.GA (AS 7.2.0.Final-redhat-8) started (with errors) in 47829ms - Started 184 of 262 services (21 services failed or missing dependencies, 56 services are passive or on-demand)
有人可以帮帮我吗?
这是我的会话bean代码:
package org.jboss.as.quickstarts.greeter.domain;
import java.util.HashMap;
import java.util.Map;
import javax.ejb.Stateful;
import javax.enterprise.inject.Alternative;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceUnit;
import javax.persistence.Query;
@Stateful
public class SessionBean implements DAO {
public SessionBean() {
}
@Inject
protected EntityManagerFactory emf;
String customerName;
Integer bookID;
int quantity;
Map<Integer,Integer> shoppingCart = new HashMap<Integer,Integer>();
public void initialize(String person) throws BookException {
if (person == null) {
throw new BookException
("Null person not allowed.");
} else {
customerName = person;
}
}
public String addBook(int bookID, int quantity){
shoppingCart.put(bookID, quantity);
return "The item has been added to your cart succesfully";
}
public String removeBook(int bookID) throws BookException{
int number = shoppingCart.get(bookID);
if ( number == 0) {
throw new BookException
("The item is not in the cart.");
}
shoppingCart.remove(bookID);
return "Selected item has been removed from your cart succesfully";
}
public String updateBook(int bookID, int quantity){
shoppingCart.put(bookID, quantity);
return "The item in your cart has been updated succesfully";
}
public String checkout(Map<Integer, Integer> content){
Order order = new Order();
return "You have successfully checked out";
}
public Map<Integer, Integer> getContents(){
return shoppingCart;
}
public Customer findByPrimaryKey(int customerID){
EntityManager em = emf.createEntityManager();
Customer customer = (Customer)em.find(Customer.class, customerID);
em.close();
return customer;
}
public BookStore findByName(String name){
EntityManager em = emf.createEntityManager();
BookStore book = (BookStore)em.find(BookStore.class, name);
em.close();
return book;
}
}
这是我的persistence.xml。我忘记了什么吗?
<?xml version="1.0" encoding="UTF-8"?>
<!-- JBoss, Home of Professional Open Source Copyright 2012, Red Hat, Inc.
and/or its affiliates, and individual contributors by the @authors tag. See
the copyright.txt in the distribution for a full listing of individual contributors.
Licensed under the Apache License, Version 2.0 (the "License"); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required
by applicable law or agreed to in writing, software distributed under the
License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
OF ANY KIND, either express or implied. See the License for the specific
language governing permissions and limitations under the License. -->
<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="primary">
<!-- If you are running in a production environment, add a managed
data source, this example data source is just for development and testing! -->
<!-- The datasource is deployed as WEB-INF/greeter-quickstart-ds.xml,
you can find it in the source at src/main/webapp/WEB-INF/greeter-quickstart-ds.xml -->
<jta-data-source>java:jboss/datasources/GreeterQuickstartDS</jta-data-source>
<properties>
<!-- Properties for Hibernate -->
<property name="hibernate.hbm2ddl.auto" value="create-drop" />
<property name="hibernate.show_sql" value="false" />
</properties>
</persistence-unit>
</persistence>