我有一个带@Transactional注释的类(而不是为它的所有方法标记它).
虽然我在该类中有一个不应该注释为的方法@Transactional.
我的问题是,我可以在此方法中添加注释以将其标记为"非事务性"吗?或者我应该开始将此类中的每个单一方法标记为"事务性",不包括此方法(很多工作)
谢谢.
我有一个包(比方说packagesToScan)包含我希望持久注释的类@Entity.
在定义ApplicationContext配置时,我做了如下操作.
@Configuration
@EnableJpaRepositories("packagesToScan")
@EnableTransactionManagement
@PropertySource("server/jdbc.properties")
@ComponentScan("packagesToScan")
public class JpaContext {
...
// Other configurations
....
@Bean
public LocalContainerEntityManagerFactoryBean entityManagerFactory() {
LocalContainerEntityManagerFactoryBean emf = new LocalContainerEntityManagerFactoryBean();
emf.setDataSource(this.dataSource());
emf.setJpaVendorAdapter(this.jpaVendorAdapter());
emf.setPackagesToScan("packagesToScan");
emf.setJpaProperties(this.hibernateProperties());
return emf;
}
Run Code Online (Sandbox Code Playgroud)
在开发时,我有一些类packagesToScan不满足持久性要求(比如没有主键等),因此我不允许因为ApplicationContext安装失败而运行测试.
现在,
有什么方法可以扫描一些选定的类或忽略其中的一些类packagesToScan?
经过一番阅读后我才看到了
if (optional.isPresent()) {
//do smth
}
Run Code Online (Sandbox Code Playgroud)
不是使用Optional的首选方法(http://www.oracle.com/technetwork/articles/java/java8-optional-2175753.html).但如果我有这样的if语句:
if (optional.isPresent()) {
car = getCar(optional.get());
} else {
car = new Car();
car.setName(carName);
}
Run Code Online (Sandbox Code Playgroud)
这是最好的方法吗?还是有更推荐的方法?
我遵循我编译的代码 gcc
#include<stdio.h>
#include<stdbool.h>
#define true 9
int main() {
printf("TRUE = %d\n",true);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我得到错误
test.c:3:0: warning: "true" redefined [enabled by default]
In file included from test.c:2:0:
/usr/lib/gcc/x86_64-linux-gnu/4.7/include/stdbool.h:34:0: note: this is the location of the previous definition
Run Code Online (Sandbox Code Playgroud)
但是当我改变代码时
#include<stdio.h>
#define true 9
#include<stdbool.h>
int main() {
printf("TRUE = %d\n",true);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
TRUE = 1
Run Code Online (Sandbox Code Playgroud)
题:
我在第一种情况下理解错误的原因但在第二种情况下,当我true在我之前定义时#include<stdbool.h>,为什么允许重新定义true?
更新:
这是stdbool.h.
前几行是
#ifndef _STDBOOL_H
#define _STDBOOL_H
#ifndef __cplusplus
#define bool _Bool …Run Code Online (Sandbox Code Playgroud) 我想知道是否Spring MVC可以用于在Java Swing应用程序中实现MVC模式.我做了一些研究,发现Spring MVC用于Web开发.
有没有什么方法可以将Spring MVC用于Swing应用程序?
我目前正在替换所有标准POJO,以便将Lombok用于所有样板代码.
到目前为止还没有出现任何问题,但是我在lombok实现中缺少的是没有生成的方法可以将一个对象添加到集合中.
生成代码:
private List<Object> list = new ArrayList<>();
public Object getObject(){..}
public void setObject(List<Object> o){..}
Run Code Online (Sandbox Code Playgroud)
我需要额外的东西:
public void addObject(Object o) {..}
Run Code Online (Sandbox Code Playgroud)
任何人都知道这是否很快到达那里或者这是不可能的?
我有接下来的两个实体,它们之间有OneToOne关系:
@Entity
@Table(name = "tasks")
public class Task {
@OneToOne(mappedBy = "task", cascade = CascadeType.PERSIST)
private Tracker tracker;
/* More code */
}
@Entity
@Table(name = "trackers")
public class Tracker {
@OneToOne
@JoinColumn(name = "trk_task", unique = true)
private Task task;
/* More code */
}
Run Code Online (Sandbox Code Playgroud)
我正在尝试运行此代码:
Task task = taskService.findDispatchableTask();
if (task != null) {
Tracker tracker = trackerService.findIdleTracker();
if (tracker != null) {
task.setTracker(tracker);
task.setStatus(TaskStatus.DISPATCHED);
taskService.save(task);
}
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:
ERROR org.hibernate.AssertionFailure - an assertion failure occured (this may …Run Code Online (Sandbox Code Playgroud) 将 kotlin 与 gradle 一起使用时,compileKotlin在compileJava. 我需要在compileJava之前执行compileKotlin。我试过了,compileKotlin.dependsOn(compileJava)但它导致循环依赖构建失败。
我也试过
compileJava.dependsOn = compileJava.taskDependencies.values - compileKotlin
但是,它仍然在compileKotlin之前执行compileJava。
我compileJava之前如何执行compileKotlin?
Apache commons-lang有两个重载BooleanUtils.and方法.
public static boolean and(final boolean... array) {
public static Boolean and(final Boolean... array) {
调用BooleanUtils.and方法时,抛出模糊方法调用错误.
java: reference to and is ambiguous
both method and(boolean...) in org.apache.commons.lang3.BooleanUtils and method and(java.lang.Boolean...) in org.apache.commons.lang3.BooleanUtils match
Run Code Online (Sandbox Code Playgroud)
可以使用以下语法调用它.
BooleanUtils.and(new Boolean[]{Boolean.TRUE, Boolean.TRUE});
但是,根据方法的javadoc,使用细节是不同的.
java ×4
spring ×4
c ×2
hibernate ×2
jpa ×2
gcc ×1
gradle ×1
if-statement ×1
include ×1
java-8 ×1
jta ×1
kotlin ×1
lombok ×1
optional ×1
persistence ×1
spring-data ×1
spring-mvc ×1
swing ×1
transactions ×1