- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在尝试获取实体 MonitorFolder 列表时遇到错误。
这就是我构建类MonitorFolder的方式
package dataObjectLayer;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;
import javax.persistence.*;
@Entity
@Table(name = "monitor_folder",
uniqueConstraints = {@UniqueConstraint(columnNames = "monitor_folder_id", name = "uc_monitorFolderId_monitor_folder"),
@UniqueConstraint(columnNames = "path", name = "uc_pathFolder_monitor_folder")
})
public class MonitorFolder {
private int monitorFolderId;
private String dateMonitored;
private String timeMonitored;
private String pathFolder;
private User owner;
public MonitorFolder() {
}
public MonitorFolder(int monitorFolderId, String dateMonitored, String timeMonitored, String pathFolder) {
this.monitorFolderId = monitorFolderId;
this.dateMonitored = dateMonitored;
this.timeMonitored = timeMonitored;
this.pathFolder = pathFolder;
}
public MonitorFolder(User owner) {
this.owner = owner;
}
@Column(name = "monitor_folder_id", length = 10)
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public int getMonitorFolderId() {
return monitorFolderId;
}
public void setMonitorFolderId(int monitorFolderId) {
this.monitorFolderId = monitorFolderId;
}
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "user_id")
@OnDelete(action = OnDeleteAction.CASCADE)
public User getOwner() {
return owner;
}
public void setOwner(User owner) {
this.owner = owner;
}
@Column(name = "date_monitored")
public String getDateMonitored() {
return dateMonitored;
}
public void setDateMonitored(String dateMonitored) {
this.dateMonitored = dateMonitored;
}
@Column(name = "time_monitored")
public String getTimeMonitored() {
return timeMonitored;
}
public void setTimeMonitored(String timeMonitored) {
this.timeMonitored = timeMonitored;
}
@Column(name = "path")
public String getPathFolder() {
return pathFolder;
}
public void setPathFolder(String pathFolder) {
this.pathFolder = pathFolder;
}
}
MonitorFolder 和 User 之间也存在多对一关系。
现在,我尝试使用以下HQL查询获取由用户ID监控的所有文件夹:
public List<MonitorFolder> selectMonitoredFoldersByUser(User owner, SessionFactory sf) throws PersistenceException {
List<MonitorFolder> monitorFolders = null;
try (Session s = sf.openSession()) {
String hql = " from MonitorFolder mf join fetch User u on u.userId = :insertedUserId";
Query <MonitorFolder> q = s.createQuery(hql);
q.setParameter("insertedUserId", owner.getUserId());
monitorFolders = q.getResultList();
}
return monitorFolders;
}
但我收到以下错误:
javax.xml.ws.WebServiceException: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: javax.xml.bind.JAXBException: class [Ljava.lang.Object; nor any of its super class is known to this context.
javax.xml.bind.JAXBException: class [Ljava.lang.Object; nor any of its super class is known to this context.]
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:403)
at com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:154)
at com.sun.xml.ws.api.message.MessageWrapper.writeTo(MessageWrapper.java:199)
at com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:134)
at com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:242)
at com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:432)
at com.sun.xml.ws.transport.http.HttpAdapter.access$100(HttpAdapter.java:100)
at com.sun.xml.ws.transport.http.HttpAdapter$1.onCompletion(HttpAdapter.java:534)
at com.sun.xml.ws.server.WSEndpointImpl$1.onCompletion(WSEndpointImpl.java:326)
at com.sun.xml.ws.api.pipe.Fiber.completionCheck(Fiber.java:867)
at com.sun.xml.ws.api.pipe.Fiber.run(Fiber.java:774)
at com.sun.xml.ws.api.pipe.Fiber.start(Fiber.java:425)
at com.sun.xml.ws.server.WSEndpointImpl.processAsync(WSEndpointImpl.java:349)
at com.sun.xml.ws.server.WSEndpointImpl.process(WSEndpointImpl.java:359)
at com.sun.xml.ws.transport.http.HttpAdapter.invokeAsync(HttpAdapter.java:530)
at com.sun.xml.ws.transport.http.servlet.ServletAdapter.invokeAsync(ServletAdapter.java:206)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doGet(WSServletDelegate.java:159)
at com.sun.xml.ws.transport.http.servlet.WSServletDelegate.doPost(WSServletDelegate.java:194)
at com.sun.xml.ws.transport.http.servlet.WSServlet.doPost(WSServlet.java:80)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:661)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:478)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:799)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:868)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1457)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.base/java.lang.Thread.run(Thread.java:835)
Caused by: javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.SAXException2: javax.xml.bind.JAXBException: class [Ljava.lang.Object; nor any of its super class is known to this context.
javax.xml.bind.JAXBException: class [Ljava.lang.Object; nor any of its super class is known to this context.]
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:276)
at com.sun.xml.bind.v2.runtime.BridgeImpl.marshal(BridgeImpl.java:104)
at com.sun.xml.bind.api.Bridge.marshal(Bridge.java:145)
at com.sun.xml.ws.db.glassfish.BridgeWrapper.marshal(BridgeWrapper.java:170)
at com.sun.xml.ws.message.jaxb.JAXBMessage.writePayloadTo(JAXBMessage.java:394)
... 42 more
Caused by: com.sun.istack.SAXException2: javax.xml.bind.JAXBException: class [Ljava.lang.Object; nor any of its super class is known to this context.
javax.xml.bind.JAXBException: class [Ljava.lang.Object; nor any of its super class is known to this context.
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:247)
at com.sun.xml.bind.v2.runtime.XMLSerializer.reportError(XMLSerializer.java:262)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:653)
at com.sun.xml.bind.v2.runtime.property.ArrayElementProperty.serializeListBody(ArrayElementProperty.java:169)
at com.sun.xml.bind.v2.runtime.property.ArrayERProperty.serializeBody(ArrayERProperty.java:159)
at com.sun.xml.bind.v2.runtime.ClassBeanInfoImpl.serializeBody(ClassBeanInfoImpl.java:361)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:696)
at com.sun.xml.bind.v2.runtime.MarshallerImpl.write(MarshallerImpl.java:271)
... 46 more
Caused by: javax.xml.bind.JAXBException: class [Ljava.lang.Object; nor any of its super class is known to this context.
at com.sun.xml.bind.v2.runtime.JAXBContextImpl.getBeanInfo(JAXBContextImpl.java:593)
at com.sun.xml.bind.v2.runtime.XMLSerializer.childAsXsiType(XMLSerializer.java:648)
... 51 more
这是否与我返回一个 JAXB 无法编码的 MonitorFolder 类型的通用列表有关?
最佳答案
问题是 hql 没有明确告诉它将返回什么类型的对象。我改变了:
from MonitorFolder mf join fetch User u on u.userId = :insertedUserId
至:
select mf from MonitorFolder mf join fetch User u on u.userId = :insertedUserId
关于java - 尝试使用 Hibernate HQL 返回一组对象时抛出异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58252087/
我的一位教授给了我们一些考试练习题,其中一个问题类似于下面(伪代码): a.setColor(blue); b.setColor(red); a = b; b.setColor(purple); b
我似乎经常使用这个测试 if( object && object !== "null" && object !== "undefined" ){ doSomething(); } 在对象上,我
C# Object/object 是值类型还是引用类型? 我检查过它们可以保留引用,但是这个引用不能用于更改对象。 using System; class MyClass { public s
我在通过 AJAX 发送 json 时遇到问题。 var data = [{"name": "Will", "surname": "Smith", "age": "40"},{"name": "Wil
当我尝试访问我的 View 中的对象 {{result}} 时(我从 Express js 服务器发送该对象),它只显示 [object][object]有谁知道如何获取 JSON 格式的值吗? 这是
我有不同类型的数据(可能是字符串、整数......)。这是一个简单的例子: public static void main(String[] args) { before("one"); }
嗨,我是 json 和 javascript 的新手。 我在这个网站找到了使用json数据作为表格的方法。 我很好奇为什么当我尝试使用 json 数据作为表时,我得到 [Object,Object]
已关闭。此问题需要 debugging details 。目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and the
我听别人说 null == object 比 object == null check 例如: void m1(Object obj ) { if(null == obj) // Is thi
Match 对象 提供了对正则表达式匹配的只读属性的访问。 说明 Match 对象只能通过 RegExp 对象的 Execute 方法来创建,该方法实际上返回了 Match 对象的集合。所有的
Class 对象 使用 Class 语句创建的对象。提供了对类的各种事件的访问。 说明 不允许显式地将一个变量声明为 Class 类型。在 VBScript 的上下文中,“类对象”一词指的是用
Folder 对象 提供对文件夹所有属性的访问。 说明 以下代码举例说明如何获得 Folder 对象并查看它的属性: Function ShowDateCreated(f
File 对象 提供对文件的所有属性的访问。 说明 以下代码举例说明如何获得一个 File 对象并查看它的属性: Function ShowDateCreated(fil
Drive 对象 提供对磁盘驱动器或网络共享的属性的访问。 说明 以下代码举例说明如何使用 Drive 对象访问驱动器的属性: Function ShowFreeSpac
FileSystemObject 对象 提供对计算机文件系统的访问。 说明 以下代码举例说明如何使用 FileSystemObject 对象返回一个 TextStream 对象,此对象可以被读
我是 javascript OOP 的新手,我认为这是一个相对基本的问题,但我无法通过搜索网络找到任何帮助。我是否遗漏了什么,或者我只是以错误的方式解决了这个问题? 这是我的示例代码: functio
我可以很容易地创造出很多不同的对象。例如像这样: var myObject = { myFunction: function () { return ""; } };
function Person(fname, lname) { this.fname = fname, this.lname = lname, this.getName = function()
任何人都可以向我解释为什么下面的代码给出 (object, Object) 吗? (console.log(dope) 给出了它应该的内容,但在 JSON.stringify 和 JSON.parse
我正在尝试完成散点图 exercise来自免费代码营。然而,我现在只自己学习了 d3 几个小时,在遵循 lynda.com 的教程后,我一直在尝试确定如何在工具提示中显示特定数据。 This code
我是一名优秀的程序员,十分优秀!