我正在使用 JPA 在 Java EE(泽西岛)中创建一个应用程序,其中未初始化的实体存在问题。我有 3 个实体 Car、Owner、House,其中汽车可以有多个所有者,所有者可以拥有多个房屋。当我返回 (entityManager.find) Car 时,所有者被初始化。当我返回 House 时,Owner 已初始化,但 Car 未初始化。我希望能够调用 House.getOwner().getCar().getId() 之类的东西。现在我必须在 House 上调用 find,然后在 Owner 上调用 find 来获取 Car。我该如何解决?
@Entity
@Table(name = "House")
public class HouseEntity {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "owner_id", nullable = false)
private OwnerEntity owner;
}
@Entity
@Table(name = "Owner")
public class OwnerEntity {
@Id
@Column(name = "id")
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = …Run Code Online (Sandbox Code Playgroud) 我在Jersey(在WildFly 8.1.0.Final上部署)上进行了RESTful应用程序,但是测试方法@DELETE出现问题。所有其他(GET,POST,PUT)均按预期工作。但是,在调用@DELETE时,我收到以下错误消息
Cross-Origin Resource Sharing (CORS) Filter: Unsupported HTTP method: DELETE
Run Code Online (Sandbox Code Playgroud)
我通过Google Chrome:高级REST客户端中的插件测试RESTful接口。我该如何解决?
资源类:为了更好地说明,我删除了其他方法。
@Path(value = "destination")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public class DestinationResource {
public DestinationResource() {}
@DELETE
@Path(value = "/{id}")
public Response deleteDestination(@PathParam("id") Long id) {
//Doing something
return Response.status(Response.Status.OK).build();
}
Run Code Online (Sandbox Code Playgroud)
}
编辑:我添加了CORS.filter,但仍然可以正常工作。这是我的web.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 container,
see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html#d4e194 -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param> …Run Code Online (Sandbox Code Playgroud) 我有Sonar分析的Android项目.我看到了所有问题但没有通过单元测试覆盖.我尝试了很多东西,但仍然无法使其正常工作.当我调用'gradlew createDebugCoverageReport'时,它将在build/reports/coverage/debug中创建包含大量文件(如report.xml和index.html)的目录,其中包含测试覆盖率数据.但在Coars的Coverage下,我得到的信息是"此组件没有覆盖详细信息".我怎样才能让它发挥作用?
命令序列:
gradlew clean assemble
gradlew createDebugCoverageReport
gradlew sonarRunner
Run Code Online (Sandbox Code Playgroud)
的build.gradle
apply plugin: 'com.android.application'
android {
compileSdkVersion 21
buildToolsVersion "21.1.2"
defaultConfig {
applicationId "cz.meteocar.unit"
minSdkVersion 16
targetSdkVersion 20
versionCode 3
versionName "1.0.2"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
debug {
debuggable true
testCoverageEnabled = true
}
}
}
apply plugin: 'sonar-runner'
sonarRunner {
sonarProperties {
property "sonar.host.url", "http://localhost:9000" // Address of Sonar server
property "sonar.sources", "src/main/java" // Sources
property "sonar.projectName", "Meteocar" // Name of your …Run Code Online (Sandbox Code Playgroud) android unit-testing build.gradle android-gradle-plugin sonarqube
我试图通过本教程WADL生成工具使用maven-wadl-plugin生成WADL .但我总是得到以下错误.有人能告诉我问题在哪里,因为我无法看到它.刚才添加了pom.xml.
这是以下错误.
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building AMS Airlines 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-wadl-plugin:1.18.1:generate (default-cli) @ ams-airlines ---
[INFO] Loading wadlGenerator com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc
[INFO] Loading wadlGenerator com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport
?íj 26, 2014 12:55:59 DOP. com.sun.xml.internal.bind.v2.util.XmlFactory createParserFactory
SEVERE: null
org.xml.sax.SAXNotRecognizedException: http://javax.xml.XMLConstants/feature/secure-processing
at org.apache.xerces.parsers.AbstractSAXParser.setFeature(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.setFeatures(Unknown Source)
at org.apache.xerces.jaxp.SAXParserImpl.<init>(Unknown Source)
at org.apache.xerces.jaxp.SAXParserFactoryImpl.newSAXParserImpl(Unknown Source)
at org.apache.xerces.jaxp.SAXParserFactoryImpl.setFeature(Unknown Source)
at com.sun.xml.internal.bind.v2.util.XmlFactory.createParserFactory(XmlFactory.java:114)
at com.sun.xml.internal.bind.v2.runtime.unmarshaller.UnmarshallerImpl.getXMLReader(UnmarshallerImpl.java:139)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:157)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:162)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:171)
at javax.xml.bind.helpers.AbstractUnmarshallerImpl.unmarshal(AbstractUnmarshallerImpl.java:189)
at com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc.init(WadlGeneratorApplicationDoc.java:147)
at com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport.init(WadlGeneratorGrammarsSupport.java:150)
at com.sun.jersey.wadl.GenerateWadlMojo.executeWithClasspath(GenerateWadlMojo.java:156)
at …Run Code Online (Sandbox Code Playgroud)