我们有一个JPA应用程序(使用hibernate),我们需要调用一个需要JDBC数据库连接作为参数的旧报告工具.是否有一种简单的方法可以访问hibernate设置的JDBC连接?
我们有一个多模块maven项目,它使用一个定义buildnumber-maven-plugin的配置文件来增加内部版本号,然后将其检入源代码控制.
如果我在父pom.xml中定义插件,它也会为所有子构建执行.
这是我的父pom.xml
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.webwars</groupId>
<artifactId>parent</artifactId>
<packaging>pom</packaging>
<properties>
<buildNumber.properties>${basedir}/../parent/buildNumber.properties</buildNumber.properties>
</properties>
<version>1.0-SNAPSHOT</version>
<name>Parent Project</name>
<profiles>
<profile>
<id>release</id>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<debug>false</debug>
<optimize>true</optimize>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
<version>1.0-beta-3</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>create</goal>
</goals>
</execution>
</executions>
<configuration>
<buildNumberPropertiesFileLocation>${buildNumber.properties}</buildNumberPropertiesFileLocation>
<getRevisionOnlyOnce>true</getRevisionOnlyOnce>
<doCheck>false</doCheck>
<doUpdate>false</doUpdate>
<format>{0, number}</format>
<items>
<item>buildNumber</item>
</items>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-scm-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>checkin</goal>
</goals>
</execution>
</executions>
<configuration>
<basedir>${basedir}</basedir>
<includes>buildNumber.properties</includes>
<message>[Automated checkin] of ${basedir} Build version: ${major.version}.${minor.version}.${buildNumber}</message>
<developerConnectionUrl>...</developerConnectionUrl>
</configuration> …Run Code Online (Sandbox Code Playgroud) 我在eclipse helios中创建了一个带有单个子模块的最小maven项目.
在src/test/resources文件夹中,我放了一个文件"install.xml".在文件夹src/test/java中,我创建了一个包含单个类的包:
@Test
public void doit() throws Exception {
URL url = this.getClass().getClassLoader().getResource("install.xml");
System.out.println(url.getPath());
}
Run Code Online (Sandbox Code Playgroud)
但是当我将代码作为junit 4单元测试运行时,我只得到一个NullPointerException.这之前已经运行了数百万次.有任何想法吗?
我遵循了这个指南:
http://www.fuyun.org/2009/11/how-to-read-input-files-in-maven-junit/
但仍然得到相同的错误.
分离通过EntityManager获取的特定JPA实体Bean的最简单方法是什么?或者,我可以让查询首先返回分离的对象,这样它们基本上可以作为"只读"吗?
我想这样做的原因是因为我想修改bean中的数据 - 仅在我的应用程序中,但不会将其持久保存到数据库中.在我的程序中,我最终必须在EntityManager上调用flush(),它会将所有更改从附加实体持久保存到underyling数据库,但我想排除特定对象.
我在开发中使用Eclipse,Maven和Java.我使用Maven下载依赖项(jar文件和javadoc可用时)和Maven的eclipse插件来生成Eclipse的.project和.classpath文件.当下载的依赖项没有连接javadoc时,我在.classpath文件中手动添加javadoc的链接,这样我就可以在Eclipse中看到依赖项的javadoc.然后,当我运行Maven的eclipse插件来重新生成.classpath文件时,它当然会消除这种变化.
有没有办法配置Maven的eclipse插件,以便在运行Maven的eclipse插件时自动为javadoc添加类路径属性?
我只对那些没有为maven资源库中的依赖项提供javadoc和/或源代码的答案感兴趣,这种情况最常见.使用downloadSources和/或downloadJavadocs属性将无助于此问题.
有没有人知道使用maven和eclipse用GWT的新2.0版本创建项目的好指南?我遇到很多问题让他们一起玩得很好.
为了它的价值,我可以使用maven eclipse插件创建一个gwt项目,它工作正常,但将其移植到maven不起作用(所以这个指南会很棒).
同样,我可以使用maven插件(gwt-maven-plugin),但是当我将它导入eclipse(import - >实现maven项目)时,它不会被识别为GWT项目......
谢谢
我继承了一个使用Hibernate 3.0连接到SQL Server数据库的Websphere Portal项目.
这个项目中大约有130个Hibernate表类.它们都实现了Serializable.它们都没有声明serialVersionUID字段,因此Eclipse IDE会显示所有这些类的警告.
这些类是否真的需要实现Serializable?
如果是这样,是否有任何工具可以同时将生成的serialVersionUID字段添加到大量类中(只是为了使警告消失)?
通常,我使用Hibernate的@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)来缓存@Entity类,它运行良好.
在JPA2中,还有另一个@Cacheable注释,它似乎与Hibernate的@Cache具有相同的功能.为了使我的实体类独立于hibernate的包,我想尝试一下.但我不能让它发挥作用.每次简单的id查询仍然会访问数据库.
谁能告诉我哪里出错了?谢谢.
实体类:
@Entity
//@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Cacheable(true)
public class User implements Serializable
{
// properties
}
Run Code Online (Sandbox Code Playgroud)
测试类:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:app.xml"})
@TransactionConfiguration(transactionManager="transactionManager")
public class UserCacheTest
{
@Inject protected UserDao userDao;
@Transactional
@Test
public void testGet1()
{
assertNotNull(userDao.get(2L));
}
@Transactional
@Test
public void testGet2()
{
assertNotNull(userDao.get(2L));
}
@Transactional
@Test
public void testGet3()
{
assertNotNull(userDao.get(2L));
}
}
Run Code Online (Sandbox Code Playgroud)
测试结果显示每个"get"命中DB层(使用hibernate.show_sql = true).
Persistence.xml:
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect"/>
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.use_outer_join" value="true"/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.SingletonEhCacheProvider"/>
<property …Run Code Online (Sandbox Code Playgroud)