我正在努力寻找原生查询InheritanceType.JOINED.从我发现的Hibernate 文档中:
13.1.6.处理继承
查询作为继承的一部分映射的实体的本机SQL查询必须包括基类及其所有子类的所有属性.
使用以下两个实体:
@Data
@Entity
@Table(name = "my_super")
@EqualsAndHashCode(of = {"id"})
@Inheritance(strategy = InheritanceType.JOINED)
public abstract class MySuper {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private long id;
}
Run Code Online (Sandbox Code Playgroud)
和:
@Data
@Entity
@Table(name = "my_sub_a")
@EqualsAndHashCode(callSuper = true)
public class MySubA extends MySuper {
@Column(name = "x")
private int x;
}
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下方法创建本机查询时:
Object actual = session
.createNativeQuery("SELECT {s.*} FROM my_super {s} LEFT JOIN my_sub_a {a} USING (id)")
.addEntity("s", MySuper.class)
.getSingleResult();
Run Code Online (Sandbox Code Playgroud)
它转换为查询:
SELECT s.id as …Run Code Online (Sandbox Code Playgroud) 我面临以下问题.我已使用以下配置设置了checkstyle:
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>${checkstyle.plugin.version}</version>
<inherited/>
<configuration>
<configLocation>${basedir}/checkstyle.xml</configLocation>
<includeTestSourceDirectory>true</includeTestSourceDirectory>
</configuration>
</plugin>
</plugins>
</reporting>
Run Code Online (Sandbox Code Playgroud)
我跑的时候运行正常mvn site.但是,当我运行checkstyle mvn checkstyle:checkstyle以便更有效地获取XML报告时,checkstyle插件会失败以使用默认配置.当我将插件移动到<build>XML时,生成正确,但现在checkstyle报告不再包含在生成的站点中.
将报表插件设置为Checkstyle 的(当前)方式是什么,同时在相同配置下单独运行插件的能力是什么?
它真的是两次定义插件和配置的首选方式吗?
我正在尝试使用JSF和Weld CDI配置Jetty.按照本手册后,我偶然发现了以下堆栈跟踪:
Caused by: java.lang.IllegalStateException: Singleton not set for STATIC_INSTANCE => []
at org.jboss.weld.bootstrap.api.helpers.RegistrySingletonProvider$RegistrySingleton.get(RegistrySingletonProvider.java:28)
at org.jboss.weld.Container.instance(Container.java:55)
at org.jboss.weld.SimpleCDI.<init>(SimpleCDI.java:77)
at org.jboss.weld.environment.WeldProvider$EnvironmentCDI.<init>(WeldProvider.java:45)
at org.jboss.weld.environment.WeldProvider.getCDI(WeldProvider.java:61)
at javax.enterprise.inject.spi.CDI.current(CDI.java:60)
at org.jboss.weld.servlet.WeldInitialListener.contextInitialized(WeldInitialListener.java:94)
at org.jboss.weld.servlet.api.helpers.ForwardingServletListener.contextInitialized(ForwardingServletListener.java:34)
at org.jboss.weld.environment.servlet.EnhancedListener.onStartup(EnhancedListener.java:65)
at org.eclipse.jetty.plus.annotation.ContainerInitializer.callStartup(ContainerInitializer.java:140)
at org.eclipse.jetty.annotations.ServletContainerInitializersStarter.doStart(ServletContainerInitializersStarter.java:63)
... 50 more
Run Code Online (Sandbox Code Playgroud)
有人看到这里出了什么问题吗?
我使用Resteasy-Guice将Resteasy与Google Guice结合使用.我一直在寻找验证我的请求主体的方法.我想做的例如:
public static class MyPojo {
@NotEmpty private String contents;
}
Run Code Online (Sandbox Code Playgroud)
然后在我的资源中使用
@POST
@ValidateRequest
public void doPost(@Valid MyPojo myPojo) {
// use myPojo only if valid
}
Run Code Online (Sandbox Code Playgroud)
我一直在使用resteasy-hibernate-validator-provider.但是,自从我切换到更新的版本后,这就引入了(不需要的?)依赖关系到EJB.另请参见:RESTEASY-1056.在评论中声明您应该切换到较新的验证器-11:
切换到resteasy-validator-provider-11,它实现了更新的Bean Validation 1.1规范.
该文件说:
默认情况下启用验证(假设resteasy-validator-provider-11-.jar可用),但可以在validation.xml配置文件中关闭或修改参数和返回值验证.有关详细信息,请参阅Hibernate Validator文档.
然而,我不设法得到这个工作,我的配置,因为我发现自己包括像依赖性hibernate-validator,javax.el-api,javax.el和hibernate-validator-cdi 和注释喜欢ValidateOnExecution.但是,我没有发现任何实例化或无效请求被拒绝.
使用Resteasy进行验证的首选,轻量级和工作方式是什么?
来自Guice背景,我知道可以使用范围从范围中播种对象值.
scope.seed(Key.get(SomeObject.class), someObject);
Run Code Online (Sandbox Code Playgroud)
我想通过注册一个从a获取值的Bean可以做到这一点AbstractBoundContext,但是从自定义范围中播种一个值的示例似乎很难找到.如何创建一个自定义范围,该范围可以为可以注入其他位置的值提供种子?
编辑:
我目前正在使用以下解决方法,可以在拦截器中注入以设置Configuration何时进入范围,然后可以通过其线程本地提供程序注入.我仍然在寻找那些感觉不那么hacky /与Weld中的范围/范围上下文系统更加集成的选项.
@Singleton
public class ConfigurationProducer {
private final InheritableThreadLocal<Configuration> threadLocalConfiguration =
new InheritableThreadLocal<>();
@Produces
@ActiveDataSet
public ConfigurationConfiguration() {
return threadLocalConfiguration.get()
}
public void setConfiguration(Configuration configuration) {
threadLocalConfiguration.set(configuration);
}
}
Run Code Online (Sandbox Code Playgroud) 是否可以使用提供的比较器反序列化 SortedSet 或 TreeSet(或者事实上 SortedMap 或 TreeMap)?
我在为要素图层设置图标时遇到了一些问题.我不断得到layer.setIcon is not a function和类似的错误.如何更改此图层的图标样式?
var layer = L.mapbox.featureLayer()
.loadURL(attrs.geoJsonSource)
.addTo(map);
layer.on('ready', function() {
this.eachLayer(function(layer){
layer.setIcon(L.mapbox.marker.icon({
'marker-color': '#8834bb',
'marker-size': 'large',
'marker-symbol': 'restaurant'
}))
});
map.fitBounds(featureLayer.getBounds());
});
Run Code Online (Sandbox Code Playgroud) 我正在玩bindToController指令选项.我偶然发现使用子范围的行为与孤立范围之间看似奇怪的区别.当我使用隔离范围时,会为该指令创建一个新范围,但对绑定控制器属性的更改将转发到父范围.然而,当我使用子范围时,我的例子就破了.(bindToController根据http://blog.thoughtram.io/angularjs/2015/01/02/exploring-angular-1.3-bindToController.html#improvements-in-14,应允许使用子范围)
代码:
{
restrict: 'E',
scope: {},
controller: 'FooDirCtrl',
controllerAs: 'vm',
bindToController: {
name: '='
},
template: '<div><input ng-model="vm.name"></div>'
};
Run Code Online (Sandbox Code Playgroud)
工作演示https://jsfiddle.net/tthtznn2/
使用子范围的版本:
{
restrict: 'E',
scope: true,
controller: 'FooDirCtrl',
controllerAs: 'vm',
bindToController: {
name: '='
},
template: '<div><input ng-model="vm.name"></div>'
};
Run Code Online (Sandbox Code Playgroud)
演示:http://jsfiddle.net/ydLd1e00/
对name的更改将转发到子作用域,但不会转发到父作用域.这与绑定到隔离范围形成对比.为什么是这样?
HttpServletRequest.login(String, String)使用以下代码登录后,对以下请求我仍然会收到基本身份验证提示.为什么login功能在我的配置中不起作用?
我的终点:
@POST
@Path("login")
@Consumes(MediaType.APPLICATION_JSON)
public void login(@Valid LoginRequest loginRequest) {
try {
User user = userController.findUserByUsername(loginRequest.getUsername()).orElseThrow(NotFoundException::new);
httpServletRequest.login(loginRequest.getUsername(), loginRequest.getPassword());
log.info(securityContext); // not null now!
}
catch (ServletException e) {
throw new NotAuthorizedException(e.getMessage(), e, AuthenticationHeaderFilter.CHALLENGE);
}
}
Run Code Online (Sandbox Code Playgroud)
和我的 jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<security-domain>MyRealm</security-domain>
</jboss-web>
Run Code Online (Sandbox Code Playgroud)
我的web.xml:
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>MyRealm</realm-name>
</login-config>
<security-role>
<role-name>admin</role-name>
</security-role>
<security-role>
<role-name>user</role-name>
</security-role>
<security-constraint>
<display-name>Authenticated content</display-name>
<web-resource-collection>
<web-resource-name>Authentication required</web-resource-name>
<url-pattern>/api/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>user</role-name>
</auth-constraint>
</security-constraint>
<security-constraint>
<display-name>Anonymous …Run Code Online (Sandbox Code Playgroud)