我正在使用Gradle的Application插件为独立的Java应用程序生成安装.我有一个配置文件,我需要放在类路径上,但我似乎无法让它在sh/bat文件中正确生成类路径.此配置文件需要位于jar外部.
conf文件位于目录中,/src/dist/conf/因此当我运行installApp它时,将它安装在这样的conf目录下$APP_HOME/conf.
我尝试将此目录添加到claspath,如下所示:
startScripts.classpath.add(files('$APP_HOME/conf'))
Run Code Online (Sandbox Code Playgroud)
但是当我查看sh/bat文件中的类路径时,它会添加一个如下所示的条目:
$APP_HOME/lib/conf
Run Code Online (Sandbox Code Playgroud)
如何告诉gradle删除lib此条目的部分?
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@Table(name = "company_policies")
@DiscriminatorColumn(name = "rule_name")
public abstract class AbstractPolicyRule implements Serializable {
@Transient
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long id;
private String value;
...
}
Run Code Online (Sandbox Code Playgroud)
_
@Entity
public class Category implements Serializable {
@Transient
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue
private Long id;
@Column(name = "category_name")
private String name;
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, orphanRemoval = true)
@JoinColumn(name = "category_policy_id", referencedColumnName = "id")
private …Run Code Online (Sandbox Code Playgroud) 我有一个现有的应用程序,它将Hibernate SessionFactory用于一个数据库.我们正在添加另一个数据库来进行分析.事务永远不会交叉,所以我不需要JTA,但我确实想要将JPA EntityManager用于新数据库.
我已经设置了EntityManager和新的事务管理器,我已经认可了,但是Spring抱怨我需要对现有的@Transactional注释进行限定.我试图找到一种方法告诉Spring使用txManager作为默认值.有没有办法做到这一点?否则,我将不得不将限定符添加到所有现有的@Transactional注释中,如果可能的话我想避免这些注释.
@Bean(name = "jpaTx")
public PlatformTransactionManager transactionManagerJPA() throws NamingException {
JpaTransactionManager txManager = new JpaTransactionManager(entityManagerFactory());
return txManager;
}
@Bean
public PlatformTransactionManager txManager() throws Exception {
HibernateTransactionManager txManager = new HibernateTransactionManager(sessionFactory());
txManager.setNestedTransactionAllowed(true);
return txManager;
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误
No qualifying bean of type [org.springframework.transaction.PlatformTransactionManager] is defined: expected single matching bean but found 2:
Run Code Online (Sandbox Code Playgroud)
谢谢
我有一个jsp包含一个看起来像的CSS链接
<link type="text/css" href="/css/login-min.css" rel="stylesheet" />
Run Code Online (Sandbox Code Playgroud)
为了防止浏览器缓存css文件,我们用css login-min.css的名称和时间戳或版本号替换
login-min.css?t=432432423423...
Run Code Online (Sandbox Code Playgroud)
在蚂蚁我会做类似的事情
<tstamp>
<format property="current.time" pattern="MMddyyyyhhmmssaa" offset="-5" unit="hour" />
</tstamp>
<replace dir="${deploy.path}/${name}/WEB-INF/jsp" value="login-min.css?t=${current.time}">
<include name="includes/login_css_include.jsp" />
<replacetoken>login-min.css</replacetoken>
</replace>
Run Code Online (Sandbox Code Playgroud)
对于gradle我已经更新了jsp页面
<link type="text/css" href="/css/@loginCSS@" rel="stylesheet" />
Run Code Online (Sandbox Code Playgroud)
在build.gradle中
import org.apache.tools.ant.filters.ReplaceTokens
war {
webInf {
from ("${webAppDir}/WEB-INF/jsp") {
include: "/includes/login_css_include.jsp"
filter(ReplaceTokens, tokens: [loginCSS: 'login-min.css?v=1'])
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用.
这个有效,但它改变了源...我只想修改战争中的文件.
import org.apache.tools.ant.filters.ReplaceTokens
war {
webInf {
from ("${webAppDir}/WEB-INF/jsp/includes/login_css_include.jsp") {
it.eachFile {
ant.replace(file: it.file, token: "@loginCSS@", value: "login-min.css?v=1")
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我是个全新的朋友,我完全不正确吗?以前有人需要这样做吗?使用gradle 1.0-milestone-1.
谢谢
比方说,我有两个表Task和Company.Company有列id和name.Task有两列customerId,providerId并链接回id列Company.
使用Querydsl我如何在Company桌面上加入两次,这样我就可以获得name由customerIdand 指定的每个公司providerId?
代码可能更好地解释了我正在尝试的内容:
Configuration configuration = new Configuration(templates);
JPASQLQuery query = new JPASQLQuery(this.entityManager, configuration);
QTask task = QTask.task;
QCompany customer = QCompany.company;
QCompany provider = QCompany.company;
JPASQLQuery sql = query.from(task).join(customer).on(customer.id.eq(task.customerId))
.join(provider).on(provider.id.eq(task.providerId));
return sql.list(task.id, customer.name.as("customerName"), provider.name.as("providerName"));
Run Code Online (Sandbox Code Playgroud)
哪个生成SQL:
select task.id, company.name as customerName, company.name as providerName from task join company on company.id = …Run Code Online (Sandbox Code Playgroud) 我们在每个客户的单独数据库中有许多客户数据,这些数据库应具有相同的模式/表结构.但是,有些表在某些数据库中与其他数据库相比具有额外的列.
例如,对于客户A,存在具有列a,b,c,d的表X. 对于客户B,存在具有列a,c,d的表X. 如果它存在,我需要捕获b但如果不存在则可以忽略它.
有没有办法告诉JPA如果它们不存在则忽略这些列?@Basic(optional=true)读取完全符合我的要求,但文档表明它是出于其他目的.
正如预期的那样,我得到'字段列表'中的未知列'table.field'
PS我不能简单地将列添加到没有它们的数据库中.
我注意到如果我在Firefox中的选择框焦点(即选择:焦点)上应用变换,它首先会聚焦选择框,然后您必须再次单击选择框才能实际下拉.还有其他人经历过吗?我试图在Mozilla上找一个bug,但没有看到任何东西.
Webkit浏览器(在chrome中测试)表现得恰当.
我使用的是Firefox 3.6.7
测试用例:
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
select:focus {
-moz-transform: scale(1.05);
-webkit-transform: scale(1.05);
}
</style>
</head>
<body>
<select>
<option>One</option>
<option>Two</option>
</select>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
我在mozilla上打开了一个错误https://bugzilla.mozilla.org/show_bug.cgi?id=581604
我有一个域对象 Expense,它有一个名为initialFields的字段。
它是这样注释的:
@OneToMany(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, orphanRemoval = true)
@JoinTable(blah blah)
private final List<Field> initialFields;
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试使用 Projections 以便出于性能原因仅提取某些字段,但是这样做时 initialFields 字段始终为空。它是唯一的 OneToMany 字段,也是我试图用这种方式的投影检索的唯一字段。如果我使用常规 HQL 查询,initialFields 会适当填充,但当然我不能限制字段。
部分投影代码:
Criteria criteria = session.createCriteria(Payment.class);
criteria.createAlias("expense", "e");
ProjectionList properties = Projections.projectionList();
//Some restrictions and more fields
properties.add(Projections.property("e.initialFields"), "initialFields");
criteria.setProjection(properties);
criteria.setFetchMode("e.initialFields", FetchMode.JOIN);
criteria.setReadOnly(true);
criteria.setResultTransformer(Transformers.aliasToBean(Expense.class));
return criteria.list();
Run Code Online (Sandbox Code Playgroud)
当我打开调试并打开 show sql 时,似乎没有创建/运行拉取 initialFields 的查询。有没有人见过这样的事情?
我刚刚尝试使用 HQL 投影,通过指定我想要拉取的每个字段然后手动构建对象。在这种情况下,Hibernate 构建的 SQL 对于 initialFields 字段是不正确的。 expense1_.name as col_1_0_, . as col_2_0_, expense1_.account_id as col_3_0_ …
这里有两个查询应该完全相同,除了一个被标记为本机而另一个不是。第一个工作正常,但第二个失败incompatible data type in conversion
@Transactional(readOnly = true)
@Query(value = "select startDate from TaskMetrics where startDate between :startDate and :endDate")
List<DateTime> findStartDateByStartDateBetween(@Param("startDate") DateTime startDate,
@Param("endDate") DateTime endDate);
Run Code Online (Sandbox Code Playgroud)
这会生成查询:
select taskmetric0_.startDate as col_0_0_ from TaskMetrics taskmetric0_ where taskmetric0_.startDate between ? and ?
Run Code Online (Sandbox Code Playgroud)
带绑定
binding parameter [1] as [TIMESTAMP] - [2015-02-02 10:57:14.279]
binding parameter [2] as [TIMESTAMP] - [2015-02-04 10:57:14.281]
Run Code Online (Sandbox Code Playgroud)
-
@Transactional(readOnly = true)
@Query(nativeQuery = true, value = "select startDate from TaskMetrics where startDate between :startDate and :endDate")
List<DateTime> findStartDateBetween(@Param("startDate") …Run Code Online (Sandbox Code Playgroud) 我有一个包含另一个域对象的域对象; 称它们为A和B. B包含一个可能很大的blob(图像文件).只要我在A上只处理A一个A就不是一个问题.但是,有时我会处理成千上万的A,其中携带B上的blob会导致堆耗尽.当我处理这么多人工智能时,我真的不需要B.
有没有办法告诉Hibernate忽略特定调用的这个属性?在这种情况下,我应该只做B瞬态并手动处理更新/删除吗?
现在为了解决这个问题,我使用SQL查询来提取我想要的所有ID,然后遍历该列表,将每个域对象取出,执行我需要的操作,然后逐出它.
另外,我不能延迟加载B,因为我在servlet环境中,因此在大多数情况下访问属性之前我的Hibernate会话已关闭.
@Entity
@Table(name="A")
public class A {
private Long id
@OneToOne(fetch = FetchType.EAGER, cascade = { CascadeType.ALL }, orphanRemoval = true)
@JoinColumn(name = "a_id", referencedColumnName = "b_id", nullable = true)
@NotFound(action = NotFoundAction.IGNORE)
private B b
...getters and setters
}
@Entity
@Table(name="B")
public class B {
private Long id;
private byte[] blob;
...getters and setters
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我正在为一个字段添加一个公式:
@Formula(value = "(select count(*) from approvalGroup as a where a.isAccounting=true)")
Run Code Online (Sandbox Code Playgroud)
但是查询失败了,因为Hibernate试图在我的对象上创建一个字段'true'.
例外:
[ERROR] Unknown column 'approvalgr0_.true' in 'where clause'
Run Code Online (Sandbox Code Playgroud)
我如何告诉Hibernate这是一个常量值而不是它需要从实体对象中检索的东西?
有 Hibernate 4 版本org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener吗?
我正在尝试将我的 Spring 3.0.x + Hibernate 3.6 应用程序升级到 Spring 3.1 + Hibernate 4,但似乎找不到如何更新它。
这在我的 applicationContext 中特别引用,如下所示:
<property name="eventListeners">
<map>
<entry key="merge">
<bean
class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener" />
</entry>
</map>
</property>
Run Code Online (Sandbox Code Playgroud)
保持原样会导致异常:
Caused by: java.lang.ClassNotFoundException: org.hibernate.event.def.DefaultMergeEventListener
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1678)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1523)
Run Code Online (Sandbox Code Playgroud)
大概是因为 Hibernate 4 不再有这个类DefaultMergeEventListener了
提前致谢。