EJB3 DataSource DataSource.getConnection

在CMT J2EE环境(容器管理事务)中,当我JDNI查找DataSource对象并调用DataSource.getConnection时,使用什么事务/连接? 这个连接是(可能是分布式的)交易的一部分吗? 每次我为同一个DataSource对象调用时, getConnection()是否返回相同的Connection? 我只知道使用本机SQL语句由同一个EntityManager使用Connections。 这让我感到困惑。 据我所知,SessionContext定义了一个每次使用数据源时都使用的事务系统。 我有一个问题,在会话bean内部使用DataSource.getConnection() ,然后关闭此连接。 如果遇到问题,则发出SessionContext.setForRollBack(true) 。 因此,服务的事务上下文如何与DataSource相关? 如果我们每次使用数据源或者至少查找数据源时都会生成一个新的Connection,那么我就会有一些问题需要理解我已经知道的事情。 任何澄清都会很精彩。 我知道容器管理的事务和其他系统,但DataSource的实际行为完全超出了我。

将数据集加载到数据库时,DBUnit的NoPrimaryKeyException

当我尝试运行一个使用DBUnit的unit testing时,我得到NoPrimaryKeyException。 数据表是使用Hibernate创建的,是两个映射多对多关系的类之间的连接表。 定义关系的注释如下: @Override @ManyToMany @JoinTable(name=”offset_file_offset_entries”, joinColumns={@JoinColumn(name=”offset_entry_id”)},inverseJoinColumns={@JoinColumn(name=”file_description_id”)}) public List getOffsets() { 我用来定义数据集的XML文件中的其他条目似乎工作正常但不是连接表。 我得到以下exception: org.dbunit.dataset.NoPrimaryKeyException: offset_file_offset_entries at org.dbunit.operation.UpdateOperation.getOperationData(UpdateOperation.java:72) at org.dbunit.operation.RefreshOperation$UpdateRowOperation.(RefreshOperation.java:266) at org.dbunit.operation.RefreshOperation.createUpdateOperation(RefreshOperation.java:142) at org.dbunit.operation.RefreshOperation.execute(RefreshOperation.java:100) at org.dbunit.ext.mssql.InsertIdentityOperation.execute(InsertIdentityOperation.java:217) at uk.co.sabio.obscheduler.application.dao.AbstractBaseDatabaseTest.setUp(AbstractBaseDatabaseTest.java:57) at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runManaged(AbstractJUnit38SpringContextTests.java:332) at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.access$0(AbstractJUnit38SpringContextTests.java:326) at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests$1.run(AbstractJUnit38SpringContextTests.java:216) at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runTest(AbstractJUnit38SpringContextTests.java:296) at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runTestTimed(AbstractJUnit38SpringContextTests.java:253) at org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests.runBare(AbstractJUnit38SpringContextTests.java:213) at junit.framework.TestResult$1.protect(TestResult.java:110) at junit.framework.TestResult.runProtected(TestResult.java:128) at junit.framework.TestResult.run(TestResult.java:113) at junit.framework.TestCase.run(TestCase.java:124) at junit.framework.TestSuite.runTest(TestSuite.java:232) at junit.framework.TestSuite.run(TestSuite.java:227) at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83) at […]

我的应用程序适用于姜饼…… ICS和HC崩溃

我需要你的帮助。 我的应用程序在GingerBread上工作正常,但在ICS和HC崩溃。 这是logcat 01-14 20:26:51.831: E/AndroidRuntime(698): FATAL EXCEPTION: main 01-14 20:26:51.831: E/AndroidRuntime(698): android.os.NetworkOnMainThreadException 01-14 20:26:51.831: E/AndroidRuntime(698): at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1099) 01-14 20:26:51.831: E/AndroidRuntime(698): at java.net.InetAddress.lookupHostByName(InetAddress.java:391) 01-14 20:26:51.831: E/AndroidRuntime(698): at java.net.InetAddress.getAllByNameImpl(InetAddress.java:242) 01-14 20:26:51.831: E/AndroidRuntime(698): at java.net.InetAddress.getAllByName(InetAddress.java:220) 01-14 20:26:51.831: E/AndroidRuntime(698): at libcore.net.http.HttpConnection.(HttpConnection.java:71) 01-14 20:26:51.831: E/AndroidRuntime(698): at libcore.net.http.HttpConnection.(HttpConnection.java:50) 01-14 20:26:51.831: E/AndroidRuntime(698): at libcore.net.http.HttpConnection$Address.connect(HttpConnection.java:351) 01-14 20:26:51.831: E/AndroidRuntime(698): at libcore.net.http.HttpConnectionPool.get(HttpConnectionPool.java:86) 01-14 20:26:51.831: […]

JPAinheritance

嗨,我是JPA的新手,我无法理解它如何处理inheritance。 我有一个特定的问题我需要在不改变DB方案的情况下解决,但是如果你找不到解决方案,我会很感激使用不同的DB方案的解决方案建议(欢迎使用Hibernate / TopLink解决方案)。 如果我不清楚或您需要更多信息,请告诉我。 提前致谢! 我有这个数据库: TABLE Fruit Id Varchar (10) Primary Key size Varchar (10) fruit_type Varchar(10) TABLE Apple Id Varchar (10) Primary Key Foreign Key references Fruit.Id Apple_Property Varchar(10) 到目前为止我的实体看起来像这样: @Entity @Inheritance(strategy=InheritanceType.JOINED) @DiscriminatorColumn(name=”fruit_type”, discriminatorType=DiscriminatorType.Char) @DiscriminatorValue(value=”fruit”) public class Fruit implements Serializable { @Id protected String Id; protected String size; } @Entity @DiscriminatorValue(value=”apple”) //@PrimaryKeyJoinColumn(name=”Id” […]

限制Visual VM中的分析

我正在尝试新JDK附带的VisualVM程序。 我正在对它进行分析,并试图仅在特定包中的方法上分析CPU。 我在“仅配置文件类”中添加了以下内容: jig.* 夹具是我想要的包装。 不幸的是,我得到了不在该包或任何子包中的其他方法的结果。

在暂停时如何让活动对本地广播作出反应?

在活动暂停或停止时,通过LocalBroadcastManager发送的广播会对活动(如果有)做出反应的最佳方式是什么? 如果LocalBroadcastManager与普通广播不同,我找不到太多细节,但如果活动在后台,它似乎仍然被称为事件。 但这会导致一些问题,因为只要未显示活动,就无法进行某些UI修改。 这就是为什么我更愿意在活动重回顶峰时处理所有广播。 但是我该怎么做呢 我正在考虑一个队列,它将获取在活动恢复运行状态时执行的可运行列表。 但我认为这是某种矫枉过正,因为机器人确实有一个机制。 那么这样做的正确方法是什么?

Log4j2无法使用Sprint Boot找到日志记录实现

我试图在弹簧启动时使用log4j2时遇到此错误。 ERROR StatusLogger Log4j2 could not find a logging implementation. Please add log4j-core to the classpath. Using SimpleLogger to log to the console… 我已经遵循了这个指南: http : //docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html#howto-configure-log4j-for-logging – 并且还添加了来自https://logging.apache.org/log4j/2.x/maven-artifacts.html的两个log4j2依赖项 我的依赖:树看起来像这样: [INFO] — maven-dependency-plugin:2.10:tree (default-cli) @ musikkjulekalender — [INFO] no.saiboten:musikkjulekalender:war:1.0-SNAPSHOT [INFO] +- org.springframework.boot:spring-boot-starter-web:jar:1.4.0.RELEASE:compile [INFO] | +- org.hibernate:hibernate-validator:jar:5.2.4.Final:compile [INFO] | | +- javax.validation:validation-api:jar:1.1.0.Final:compile [INFO] | | +- […]

CQ5删除渲染阻止JavaScript

我正在编写此文档以删除阻塞js: 删除阻止JS 但是对于CQ5,我们包括js via: 如何修改脚本标签,如: 所以我可以删除阻止JS。

在单个流上组合allMatch,noneMatch和anyMatch

我想有以下逻辑:(我知道它不起作用,因为它不止一次地消耗流)。 但我不知道如何实现它。 Stream buffers = super.getBuffers().stream(); if (buffers.allMatch(b -> b.position() > 0)) { return OutgoingMessageStatus.FULLY_SENT; } else if (buffers.noneMatch(b -> b.position() > 0)) { return OutgoingMessageStatus.WAS_NOT_SENT; } else { return OutgoingMessageStatus.PARTIALLY_SENT; } 我怎样才能做到这一点?

如何获得5或10的下一个最高倍数

根据一些规则,我希望根据一些规则获得次高的数字,因为我在描述它们时遇到一些困难,我将通过例子来说明: Input Desired output ——- ————– 0.08 0.1 0.2 0.5 5 10 7 10 99 100 100 500 2345 5000 在某种意义上,输出应该是“5或10的下一个最高倍数”。 我希望这是可以理解的; 如果没有,请告诉我。 执行将在java和输入将是正double s。