我试图通过约束验证来持久化实体,当调用持久化时 - 抛出约束并且调用者得到EjbTransactionRolledbackException...所以我尝试显式调用验证并抛出ConstraintViolationException/ RuntimeException仍然调用者得到EjbTransactionRolledbackException...当我抛出MyException扩展时Exception - 来电者得到MyException
即使我打电话给sc.setRollBackOnly它显然它仍然发生:(
这不应该是行为.
这是怎么回事?
组态:
Netbeans 6.9.1 Glassfish 3.0.1 JPA 2.0(EclipseLink)EJB 3.1
谢谢!!!
@Stateless
public class My {
@PersistenceContext
EntityManager em;
@Resource
Validator validator;
public Order checkout(Order order) {
Set<ConstraintViolation<Order>> set = validator.validate(order, Default.class);
if (!set.isEmpty()) {
sc.setRollbackOnly();
//throw new ConstraintViolationException(new HashSet<ConstraintViolation<?>>(set));
throw new RuntimeException();
}
this.em.persist(order);
}
Run Code Online (Sandbox Code Playgroud) 我需要显示/编辑多态实体.
我的抽象类是Person.我的具体课程是PhysicalPerson和MoralPerson
每个具体类都有自己的自定义属性.
如何根据实体类使用适当的显示/编辑(复合)组件?
谢谢 !:)
我正在尝试创建两个实体,其中两个实体都有embeddedIds.其中一个实体有2个引用另一个实体,其中这两个引用都与ManyToOne相关.
示例代码如下:
@Embeddable
public class ItemPK {
@Column(nullable = false, length = 100)
private String itemId;
@Column(name = "item_client_id", nullable = false)
private int clientId;
...
}
@Entity
@Table(name = "item")
public class Item {
@EmbeddedId
private ItemPK id;
@ManyToOne
@JoinColumn(name = "item_client_id")
private Client client;
@OneToMany(mappedBy="item", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<RelatedItem> relatedItems;
@OneToMany(mappedBy="relatedItem", cascade = CascadeType.ALL, orphanRemoval = true)
private Set<RelatedItem> relatedItemsRHS;
...
}
@Embeddable
public class RelatedItemPK {
@Column(name = "itemId", length = 100, nullable …Run Code Online (Sandbox Code Playgroud) (使用Glassfish 3.1的Java EE 6)
我有一个属性文件,我想在启动时只处理一次,所以我这样做了
public class Config implements ServletContextListener{
private static final String CONFIG_FILE_PATH = "C:\\dev\\harry\\core.cfg";
private static final String CONFIG_ATTRIBUTE_NAME = "config";
private long startupTime;
private ConfigRecord config;
@Override
public void contextInitialized(ServletContextEvent sce) {
this.startupTime = System.currentTimeMillis() / 1000;
this.config = new ConfigRecord(CONFIG_FILE_PATH); //Parse the property file
sce.getServletContext().setAttribute(CONFIG_ATTRIBUTE_NAME, this);
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
//Nothing to do here
}
public ConfigRecord getConfig() {
return config;
}
public long getStartupTime() {
return startupTime;
}
}
Run Code Online (Sandbox Code Playgroud)
在web.xml …
使用javax.security.Principal,您可以通过注入EJBContextwith 来随时检索用户信息@Resource.
我想要做的是添加额外的信息,这些信息将特定于我的应用程序和我的用户作为一部分Principal.我也试图包括在这一信息contextData()的EJBContext,但这只持续了EJB的生命周期,而不是在多个EJB调用.
有没有办法扩展Principal添加任何额外的信息?我宁愿不使用ThreadLocal或修改我的所有EJB签名来传递此信息.
我们正在将我们的应用程序从JBoss Seam迁移到CDI(JEE6),所以我们正在改变一些像@In和@Out这样的分析,我们发现有很多信息对我们有帮助,但是我们有一些麻烦试图找出如何更换具有特定模式的anotations:
对于@In anotation
@Name("comprobantes")//context name
...
@In(create=false,value="autenticadoPOJO",required=false)
private UsuarioPOJO autenticadoPOJO;
Run Code Online (Sandbox Code Playgroud)
我们可以使用CDI中的@Inject,但是如何为这种情况设置上下文变量的名称?
对于@Out anotation
@Out(scope = ScopeType.SESSION, value = "autenticadoPOJO", required = false)
Run Code Online (Sandbox Code Playgroud)
我已经阅读了一些博客,他们说我可以在CDI中使用@Produces,我们如何在添加此anotation之前或之后设置范围?
我感谢任何帮助或任何有用的文档.
我有一个EAR文件(JEE6),其中包含一个ejb-jar(sample-ejb)文件和一个war文件(sample-web).这是结构:
sample-ear
|----sample-ejb.jar
| |---TestEjb.java (@Singleton)
|
|----sample-web
|---StartupEjb.java (@Singleton,@Startup)
|---TestListener.java (@WebListener)
Run Code Online (Sandbox Code Playgroud)
当我想将TestEjb注入StartupEjb或TestListener时:
@EJB
private TestEjb testEjb;
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Glassfish的:
Caused by: com.sun.enterprise.container.common.spi.util.InjectionException: Exception attempting to inject Remote ejb-ref name=com.sample.StartupEjb/testEjb,Remote 3.x interface =com.sample.TestEjb,ejb-link=null,lookup=,mappedName=,jndi-name=com.sample.TestEjb,refType=Session into class com.sample.StartupEjb: Lookup failed for 'java:comp/env/com.sample.StartupEjb/testEjb' in SerialContext[myEnv={java.naming.factory.initial=com.sun.enterprise.naming.impl.SerialInitContextFactory, java.naming.factory.state=com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl, java.naming.factory.url.pkgs=com.sun.enterprise.naming}
Run Code Online (Sandbox Code Playgroud)
weblogic的:
Caused By: weblogic.application.naming.ReferenceResolutionException: [J2EE:160200]Error resolving ejb-ref "com.sample.StartupEjb/testEjb" from module "sample-web-1.0-SNAPSHOT.war" of application "com.sample_sample-ear_ear_1.0-SNAPSHOT". The ejb-ref does not have an ejb-link and the JNDI name of the target bean has not been specified. Attempts to automatically link …Run Code Online (Sandbox Code Playgroud) 我正在尝试将JSF 2.1 Web应用程序部署到Weblogic 12.1应用程序服务器,但部署失败,出现以下异常
<javax.enterprise.resource.webcontainer.jsf.config> <BEA-000000>
<Critical error during deployment:
com.sun.faces.config.ConfigurationException: CONFIGURATION FAILED!
com.oracle.injection.integration.jsf.WeblogicFacesConfigResourceProvider
cannot be cast to com.sun.faces.spi.ConfigurationResourceProvider
at com.sun.faces.config.ConfigManager.initialize(ConfigManager.java:377)
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:223)
at weblogic.servlet.internal.EventsManager$FireContextListenerAction.run(EventsManager.java:582)
at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
Truncated. see log file for complete stacktrace
Run Code Online (Sandbox Code Playgroud)
我使用的是Mojarra实现版本2.1.13 - 这里是相应的pom.xml条目:
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.13</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.13</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我添加了以下行以weblogic.xml防止weblogic服务器加载运送的jsf实现:
<container-descriptor>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<prefer-application-packages>
<package-name>javax.faces.*</package-name>
<package-name>com.sun.faces.*</package-name>
<package-name>com.bea.faces.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>javax.faces.*</resource-name>
<resource-name>com.sun.faces.*</resource-name>
<resource-name>com.bea.faces.*</resource-name>
<resource-name>META-INF/services/javax.servlet.ServletContainerInitializer</resource-name>
</prefer-application-resources>
</container-descriptor>
Run Code Online (Sandbox Code Playgroud)
该WeblogicFacesConfigResourceProvider包含在weblogic.jar.
那么这里出了什么问题? - 任何提示?
好的,我找到了解决方案:你必须添加META-INF/services/com.sun.faces.spi.FacesConfigResourceProvider到 …
我是这里的新手,也是CDI世界的新手,我在工作中得到的第一项任务就是找到一种控制CDI上传的方法.
我们同时使用EJB 3.1和CDI 1.0,因为它们是由不同的容器控制的,我们可以控制何时和以何种顺序EJB管Bean将达到使用@Startup和@Singleton标注.
但是@Inject我在我的类中声明的CDI bean因为CDI容器尚未启动而变为空.
我已经尝试了好几天来寻找解决方案,而我在这里找到的解决方案没有用(仍然是空的).
我们正在使用Java EE 6并在WebSphere Application Server 8上运行该应用程序.
请问,如果你能帮我找到一种方法来控制内部和不管EJB的CDI上传?
这是一个示例代码:
import javax.annotation.PostConstruct;
import javax.ejb.Singleton;
import javax.ejb.Startup;
@Singleton
@Startup
public class BaseStartupLoader{
/**
* Default constructor.
*/
@Inject @MyStartup
BaseStartUp myStartup;
private static Logger m_logger = LoggerFactory.getLogger(BaseStartupLoader.class);
public BaseStartupLoader() {
}
@PostConstruct
public void init(){
String applicationName = null;
try {
applicationName = myStartup.getClass().getName();
myStartup.load();
} catch (IllegalAccessException e) {
m_logger.error("Faild to load data …Run Code Online (Sandbox Code Playgroud) 这是EJB3.1 Timer取消问题的后续问题
我之前在项目中使用过Spring的@Scheduled.EJB3.1 @Schedule与此类似吗?EJB3.1 @Schedule在集群环境中的表现如何?在具有多个JVM的集群环境中,我们如何确保一次只运行一个调度程序/计时器?例如,我希望每小时通过电子邮件发送给客户的数据库中的库存水平,我不希望发送重复的电子邮件.我知道如何设置数据库标志以避免进一步重复.但是,我不认为这是一个合适的解决方案.对此有什么想法吗?