我想在Hibernate(版本1.1.1-Final)(在Spring应用程序中)使用JPA 2 Meta模型生成器.因为我使用Mapped Superclass作为所有实体的基础,并且这个类位于不同的jar中(供重用)我需要在XML中显式地映射这个类(仅用于元模型生成,因为它无需任何额外的工作准时的东西)---可能有人提示如何解决这个问题,但这不是问题.
此映射的超类(BusinessEntity)使用嵌入式类(BusinessId).
@SuppressWarnings("serial")
@MappedSuperclass
public abstract class BusinessEntity<T extends Serializable>
implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Long id;
@Embedded
private BusinessId<T> businessId;
...
}
@Embeddable
public class BusinessId<T> implements Serializable {
@Column(nullable = false, unique = true, name = "businessId")
private long businessId;
...
}
Run Code Online (Sandbox Code Playgroud)
但我没有得到映射与Generator一起工作:如果我使用它 orm.xml
<?xml version="1.0" encoding="UTF-8"?>
<entity-mappings xmlns="http://java.sun.com/xml/ns/persistence/orm"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/persistence/orm
http://java.sun.com/xml/ns/persistence/orm_2_0.xsd"
version="2.0">
<mapped-superclass class="BusinessEntity"
access="FIELD">
<attributes>
<id name="id">
<column nullable="false"/>
<generated-value strategy="AUTO"/>
</id>
<embedded name="businessId"/>
</attributes>
</mapped-superclass> …Run Code Online (Sandbox Code Playgroud) 我有一个日期格式模式: MMM yyyy
并希望:如果月份名称很短,则在名称后面打印一个点.但如果月份名称不短,则不添加任何点.
例:
May 2010无点) - 5月只有3个字母,因此不需要点,因为它不是缩写.Dec. 2010带点) - 12月长度超过3个字母,因此需要一个点,因为它是缩写.这是可能的模式,还是我需要通过"手"实现它?
我正在使用Maven构建JEE6(EJB)应用程序.我使用maven依赖:
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
获得api课程.但我错过了api源代码.(比如javax.ejb ejb-api 3.0)
所以问题是我如何获得JEE6 Apis(特别是EJB 3.1)的源代码?
我需要它来更好地在Eclipse中进行代码补充和文档编制.
我有一个简单的(webprofile)EJB 3.1应用程序,并尝试确定@ApplicationScopedCDI Bean中的当前用户,所以我使用:
Principal callerPrincipal = this.sessionContext.getCallerPrincipal()
Run Code Online (Sandbox Code Playgroud)
工作正常(所以我可以确定当前用户的名称).
但是在任何(其他)EJB中的任何异常之后,此调用不再起作用(我需要重新启动服务器)!该方法不会返回调用者主体,而是抛出此异常.
Caused by: java.lang.NullPointerException
at com.sun.ejb.containers.EJBContextImpl.getCallerPrincipal(EJBContextImpl.java:421)
at de.mytest.service.CurrentUserService.getCurrentUserId(CurrentUserService.java:102)
Run Code Online (Sandbox Code Playgroud)
有人能给我一个提示我做错了吗?
实施细节:
Server Glassfish 3.1.2
CurrentUserService:
@ApplicationScoped
public class CurrentUserService {
@Resource
private SessionContext sessionContext;
public long getCurrentUserId() {
if (this.sessionContext == null) {
throw new RuntimeException("initialization error, sessionContext must not be null!");
}
/*line 102 */ Principal callerPrincipal = this.sessionContext.getCallerPrincipal();
if (callerPrincipal == null) {
throw new RuntimeException("callerPrincipal must not be null, but it is");
}
String name = callerPrincipal.getName();
if …Run Code Online (Sandbox Code Playgroud) 我有一个在Glassfish 3.1.2上运行的JSF 2,EJB 3.1,CDI应用程序.我注意到jsession id总是发生变化:每次发送到服务器的请求,重新调整的页面都包含带有新jsession id的links(),即使请求已包含jsession id
我不认为这是正常的,但我不知道是什么原因导致这种行为.
我配置了:
<session-config>
<session-properties>
<property name="enableCookies" value="false" />
<property name="enableURLRewriting" value="true" />
</session-properties>
</session-config>
Run Code Online (Sandbox Code Playgroud)
但是其他所有东西都是默认的,我没有任何奇怪的配置或自定义jsession生成的东西. - 有谁知道什么可以触发Glassfish/JSF来改变sessionId?
例:
该应用程序有一个菜单显示在每个页面上.jsf页面包含:
<h:link outcome="/search/search">search</h:link>
现在我描述请求和响应.请求是简单的HTTP GET请求.响应总是包含完整的页面.没有涉及Ajax.
经过一些基本认证.
用户进入起始页面,它包含一个带有搜索页面链接的菜单,此链接有jsession id(所有其他链接都有相同的jsessionId) - 详细信息;
http://localhost:8080/myApp/start/start.xhtml<a href="/myApp/search/search.xhtml;jsessionid=8df431e2275052cf2348a4cb793e">search</a>用户点击该链接; 返回的页面再次包含菜单,但现在所有链接都有另一个sessionjd - 详细信息:
http://localhost:8080/myApp/suche/teilnehmer_suche.xhtml;jsessionid=8df431e2275052cf2348a4cb793e<a href="/myApp/search/search.xhtml;jsessionid=8ebeefb6df144a2fee97d87a51e6">...用户再次点击该链接:jsession id再次更改
http://localhost:8080/myApp/suche/teilnehmer_suche.xhtml;jsessionid=8df431e2275052cf2348a4cb793e<a href="/myApp/search/search.xhtml;jsessionid=8f4021c2fa628ce3b9c12c545cc4">...我可以一次又一次地点击该链接(以及所有其他链接),但jsession id每次都会更改.
更奇怪的是:在更改配置以使用cookie而不是urlRewriting后,我发现即使对于资源文件也会发生此行为:
客户端请求start.xml没有jsession id,服务器返回Set-Cookie JSESSIONID=a68d3d9260d7ea5fd36a7713eb80; Path=/myapp; HttpOnly响应头.
之后客户端请求css页面,Cookie JSESSIONID=a68d3d9260d7ea5fd36a7713eb80服务器发送回css文件,但响应头包含一个新的会话ID:Set-Cookie JSESSIONID=a68d550e5093e246b01ba4220cd3; Path=/myapp; HttpOnly
我正在寻找一个可以插入Spring MVC应用程序的简单CMS,与我可以插入Spring应用程序的CMS相比.
让我先解释一下我不想要的东西:我不想要像Magnolia/Blossom这样的CMS,我可以在CMS中添加一些Spring插件.
我需要的是另一种方式; 我需要一些由我的应用程序控制的CMS.(CMS只是其中的一小部分,而不是主要部分.)
假设这两个用例:
有人知道这样的CMS吗?
假设有一个 Hibernate 4.2 JPA 2.0 实体class EntityA,它包含一个@ManyToOne字段List<EntityB> bs。到目前为止,我坚信我不能bs用newList 替换,而是必须使用 list 方法clear,add和remove。
今天,我想向一所大学展示,当我用新列表替换列表时,它会引起问题,但没有发生任何奇怪的事情,它有效,数据库和实体已正确更新。现在我很困惑:hibernate 4.x JPA 2 是否允许替换持久实体的集合?
这两个实体具有一对多关系,由单一站点维护。
@Entity
public class EntityA {
@Id long id;
@OneToMany public List<EntityB>bs;
}
@Entity
public class EntityB {
@Id long id;
hashCode and equals based on id
}
Run Code Online (Sandbox Code Playgroud)
测试了一下,没发现问题
@Test
@Transactional
public testReplaceSet {
//given: a persistent entity a that contains a persistent entity b1
EntityA a …Run Code Online (Sandbox Code Playgroud) 我有一个使用Spring HATEOAS的Spring Boot应用程序,它已@EnableEntityLinks启用.该应用程序有一个包含字段的mvc控制器@Autowired EntityLinks entityLinks.
我预计@EnableEntityLinks会提供EntityLinksbean(根据:暴露和管理与Spring HATEOAS的链接),但我得到了一个NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.hateoas.EntityLinks] found
该应用程序是一个测试应用程序,因此它非常小:
Application.java:
@ComponentScan
@EnableAutoConfiguration
@EnableEntityLinks
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Run Code Online (Sandbox Code Playgroud)
CustomerController:
@Controller
@ExposesResourceFor(Customer.class)
@RequestMapping(value = "/customers", produces = "application/json")
public class CustomerController {
@Autowired
private EntityLinks entityLinks;
@RequestMapping(method=RequestMethod.GET)
@ResponseBody
public ResponseEntity<List<Customer>> customers() {
return new ResponseEntity<List<Customer>>(HttpStatus.OK);
}
@RequestMapping(value="/{id}", method=RequestMethod.GET)
@ResponseBody
public ResponseEntity<Customer> customer(@PathVariable long id) { …Run Code Online (Sandbox Code Playgroud) 我正在使用它lesscss-maven-plugin生成不同的css文件到目标目录(target\generated-sources),然后用于maven-war-plugin将此目录添加为webResouce.这些文件将生成完美的.
但是,m2e-plugin(版本1.0.0)在更改m2e-wtp\web-resources时不会复制相应web-resources文件夹()中的那些文件.只有当我运行eclipse"maven/update project"时,才会更新更改.但我希望更改在文件更改时自动生效.这是我的pom配置:
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions><pluginExecution>
<pluginExecutionFilter>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<versionRange>[1.3.3]</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>true</runOnConfiguration>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
Run Code Online (Sandbox Code Playgroud)
....
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.3.3</version>
<configuration>
<sourceDirectory>${project.basedir}/src/main/less</sourceDirectory>
<outputDirectory>${project.build.directory}/generated-sources/styles</outputDirectory>
<lessJs>${project.basedir}/tools/less/less-1.7.0.min.js</lessJs>
<includes>
<include>backend/backend-main.less</include>
<include>frontend/frontend-main.less</include>
</includes>
</configuration>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated-sources/styles</directory>
<targetPath>styles</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud) Spring 4.1.2(4.0.8和3.2.12)包含一个安全修正程序SPR-12354,它可以阻止ResourceHttpRequestHandler(后面的东西<mvc:resources>)从资源文件夹外部加载文件.
另一方面:是JRebel(我使用它的默认配置).接下来,JRebel做了一些魔术来加载资源而不是从wtp文件夹加载,而是直接形成"source"文件夹.
因此,在从Spring 3.2.11升级到3.2.12(以及从4.0.7升级到4.0.8的其他类似应用程序)之后,Springs ResourceHttpRequestHandler不再提供由JRebel"维护"的资源文件.而是传递404.原因是Spring将配置的资源文件夹的绝对文件路径与将要传递的文件的绝对文件路径进行比较.如果ResourceHttpRequestHandler认为该文件在配置的资源文件夹之外,则它假定用于选择该文件的URL是恶意的.因此,ResourceHttpRequestHandler找不到404资源的响应.
我希望JRebel可以配置为不"维护"js,png和css文件,但我不知道如何.这就是问题:如何配置Spring MVC应用程序(v 4.0.8)仍然提供资源的JRebel ResourceHttpRequestHandler?
(我希望在升级到Spring 4.1.2,4.0.8或3.2.12之后几乎每个JRebel用户都面临这个问题).
(不要误解我的意思,这不是一个如何操纵Spring不要检查文件是否在配置资源文件夹之外的问题.我已经查看了源代码,观察到的行为是预期的行为由Bug修复的作者. - 这个问题是关于配置JRebel)