小编WSK*_*WSK的帖子

如何解决由hibernate双向映射引起的json序列化器中的循环引用?

我正在编写一个序列化程序来将POJO序列化为JSON,但却陷入循环引用问题.在hibernate双向一对多关系中,父引用子和子引用回父,这里我的序列化器死了.(参见下面的示例代码)
如何打破这个循环?我们可以获取对象的所有者树,以查看对象本身是否存在于其自己的所有者层次结构中的某个位置?任何其他方式来查找引用是否将是循环的?或任何其他想法来解决这个问题?

java serialization json hibernate

75
推荐指数
5
解决办法
9万
查看次数

org.hibernate.PersistentObjectException:传递给persist的分离实体

我用hibernate成功编写了我的第一个master child示例.几天后我再次拿起它并升级了一些图书馆.不知道我做了什么,但我再也不能让它再次运行.有人会帮助我弄清楚在返回错误消息后返回的代码中出现了什么问题:

org.hibernate.PersistentObjectException: detached entity passed to persist: example.forms.InvoiceItem
    at org.hibernate.event.def.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:127)
    at org.hibernate.impl.SessionImpl.firePersist(SessionImpl.java:799)
    at org.hibernate.impl.SessionImpl.persist(SessionImpl.java:791)
    .... (truncated)
Run Code Online (Sandbox Code Playgroud)

hibernate映射:

<hibernate-mapping package="example.forms">
    <class name="Invoice" table="Invoices">
        <id name="id" type="long">
            <generator class="native" />
        </id>
        <property name="invDate" type="timestamp" />
        <property name="customerId" type="int" />
        <set cascade="all" inverse="true" lazy="true" name="items" order-by="id">
            <key column="invoiceId" />
            <one-to-many class="InvoiceItem" />
        </set>
    </class>
    <class name="InvoiceItem" table="InvoiceItems">
        <id column="id" name="itemId" type="long">
            <generator class="native" />
        </id>
        <property name="productId" type="long" />
        <property name="packname" type="string" />
        <property name="quantity" type="int" />
        <property name="price" type="double" />
        <many-to-one …
Run Code Online (Sandbox Code Playgroud)

hibernate

75
推荐指数
4
解决办法
16万
查看次数

not-null属性引用null或transient值

使用hibernate保存父/子对象时遇到麻烦.任何想法都将受到高度赞赏.

org.hibernate.PropertyValueException: not-null property references a null or transient value: example.forms.InvoiceItem.invoice
    at org.hibernate.engine.Nullability.checkNullability(Nullability.java:100)
        .... (truncated)
Run Code Online (Sandbox Code Playgroud)

hibernate映射:

<hibernate-mapping package="example.forms">
    <class name="Invoice" table="Invoices">
        <id name="id" type="long">
            <generator class="native" />
        </id>
        <property name="invDate" type="timestamp" />
        <property name="customerId" type="int" />
        <set cascade="all" inverse="true" lazy="true" name="items" order-by="id">
            <key column="invoiceId" />
            <one-to-many class="InvoiceItem" />
        </set>
    </class>
    <class name="InvoiceItem" table="InvoiceItems">
        <id column="id" name="itemId" type="long">
            <generator class="native" />
        </id>
        <property name="productId" type="long" />
        <property name="packname" type="string" />
        <property name="quantity" type="int" />
        <property name="price" type="double" />
        <many-to-one class="example.forms.Invoice" column="invoiceId" …
Run Code Online (Sandbox Code Playgroud)

hibernate

68
推荐指数
3
解决办法
15万
查看次数

如何在具有默认命名空间的xml文档上使用XPath

我想操作具有默认命名空间但没有前缀的xml doc.有没有一种方法可以使用没有命名空间uri的xpath,就好像没有命名空间一样?
我相信如果我们将documentBuilderFactory的namespaceAware属性设置为false应该是可能的.但就我而言,它不起作用.
我的理解是不正确的还是我在代码中犯了一些错误?

这是我的代码:

    DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(false);
    try {
        DocumentBuilder builder = domFactory.newDocumentBuilder();
        Document dDoc = builder.parse("E:/test.xml");

        XPath xPath = XPathFactory.newInstance().newXPath();
        NodeList nl = (NodeList) xPath.evaluate("//author", dDoc, XPathConstants.NODESET);
        System.out.println(nl.getLength());
    } catch (Exception e) {
        e.printStackTrace();
    }
Run Code Online (Sandbox Code Playgroud)

这是我的xml:

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://www.mydomain.com/schema">
  <author>
    <book title="t1"/>
    <book title="t2"/>
  </author>
</root>
Run Code Online (Sandbox Code Playgroud)

java xml xpath

16
推荐指数
1
解决办法
3万
查看次数

我可以在HQL查询中选择null作为列值吗?

我需要一个包含三列的列表.第1列和第3列具有值,而第2列为空.我可以通过HQL查询来完成吗?

我需要这样的东西:

select id, null, name from MyClass
Run Code Online (Sandbox Code Playgroud)

MyClass以及底层表只有两个属性/列,即"id"和"name"

java orm hibernate hql

11
推荐指数
2
解决办法
1万
查看次数

为什么Roslyn生成没有空格的方法代码

罗斯林在标识符和关键字之间没有任何空格的情况下生成代码,我做错了什么?它还在方法块的末尾加上一个分号.这是我的代码:

SeparatedSyntaxList<ParameterSyntax> parametersList = new SeparatedSyntaxList<ParameterSyntax>().AddRange
(new ParameterSyntax[]
    {
        SyntaxFactory.Parameter(SyntaxFactory.Identifier("sender")).WithType(SyntaxFactory.ParseTypeName("object")),
        SyntaxFactory.Parameter(SyntaxFactory.Identifier("args")).WithType(SyntaxFactory.ParseTypeName("EventArgs"))
    }
);

MethodDeclarationSyntax newMethod = SyntaxFactory.MethodDeclaration(
    SyntaxFactory.List<AttributeListSyntax>(),
    SyntaxFactory.TokenList(SyntaxFactory.Token(SyntaxKind.PrivateKeyword)),
    SyntaxFactory.ParseName("void"),
    null,
    SyntaxFactory.Identifier("simpleButton1_Click"),
    null,
    SyntaxFactory.ParameterList(parametersList),
    SyntaxFactory.List<TypeParameterConstraintClauseSyntax>(),
    SyntaxFactory.Block(),
    SyntaxFactory.Token(SyntaxKind.SemicolonToken)
);
Run Code Online (Sandbox Code Playgroud)

以下是我的结果:

privatevoidsimpleButton1_Click(objectsender,EventArgse){};
Run Code Online (Sandbox Code Playgroud)

c# roslyn

11
推荐指数
2
解决办法
1578
查看次数

Keycloak 17.0.0 docker 镜像找不到适合 postgres 的驱动程序

我正在运行 docker 桌面(Windows)并按照此处的说明为 keycloak 17.0.0 构建 docker 映像。构建成功完成,但是当我在桌面上运行此映像时出现错误

错误 [org.key.qua.run.cli.ExecutionExceptionHandler](主要)错误:无法获取 JDBC 连接

错误 [org.key.qua.run.cli.ExecutionExceptionHandler](主要)错误:找不到适用于 jdbc 的驱动程序:postgresql://postgres/keycloak

postgres 已经在默认端口 5432 上以名称“postgres”在 docker 桌面中运行,并创建了 keyclock 数据库。

这是我的 Dockerfile:

FROM quay.io/keycloak/keycloak-x:latest as builder

ENV KC_METRICS_ENABLED=true
ENV KC_FEATURES=token-exchange
ENV KC_DB=postgres
RUN /opt/keycloak/bin/kc.sh build

FROM quay.io/keycloak/keycloak-x:latest
COPY --from=builder /opt/keycloak/lib/quarkus/ /opt/keycloak/lib/quarkus/
WORKDIR /opt/keycloak

RUN keytool -genkeypair -storepass password -storetype PKCS12 -keyalg RSA -keysize 2048 -dname "CN=server" -alias server -ext "SAN:c=DNS:localhost,IP:127.0.0.1" -keystore conf/server.keystore

ENV KEYCLOAK_ADMIN=admin
ENV KEYCLOAK_ADMIN_PASSWORD=admin

ENV KC_DB_URL='jdbc:postgresql://postgres/keycloak'
ENV KC_DB_USERNAME=postgres
ENV KC_DB_PASSWORD=postgres

ENV KC_HOSTNAME=localhost:8443
ENTRYPOINT …
Run Code Online (Sandbox Code Playgroud)

docker keycloak

10
推荐指数
1
解决办法
9137
查看次数

如何在导航子窗体中显示拆分表单?

我在MS-Access 2013应用程序中创建了拆分表单.它们可以单独运行,但是当我通过导航表单打开它们时,它们在导航子表单中显示为单个.尝试了很多选择,但无法弄清楚出了什么问题.

ms-access

9
推荐指数
1
解决办法
1万
查看次数

Tomcat/Hibernate问题"SEVERE:Error listenerStart"

我下载了hibernate的工作示例(使用maven)并将其安装在我的tomcat上,它工作正常.然后我在MyEclipse中创建了一个新的Web项目,添加了hibernate支持,并将所有源文件(没有jar)移动到这个新项目,并在必要的地方修改了包/路径.我的servlet正确响应但是当我在web.xml中添加"Listener"时,tomcat在启动时返回错误"Error ListenerStart"并且我的应用程序没有启动.
我仔细检查了所有的包,路径和类,它们看起来很好.除了这两个词之外,错误信息也没有告诉任何更多这里是完整的tomcat启动日志:

17-Jun-2010 12:13:37 PM org.apache.coyote.http11.Http11Protocol init
INFO: Initializing Coyote HTTP/1.1 on http-8810
17-Jun-2010 12:13:37 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 293 ms
17-Jun-2010 12:13:37 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
17-Jun-2010 12:13:37 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.20
17-Jun-2010 12:13:37 PM org.apache.catalina.core.StandardContext start
SEVERE: Error listenerStart
17-Jun-2010 12:13:37 PM org.apache.catalina.core.StandardContext start
SEVERE: Context [/addressbook] startup failed due to previous errors
17-Jun-2010 12:13:37 PM org.apache.coyote.http11.Http11Protocol start
INFO: Starting Coyote HTTP/1.1 on http-8810
17-Jun-2010 12:13:37 …
Run Code Online (Sandbox Code Playgroud)

tomcat hibernate servlets servlet-filters

7
推荐指数
1
解决办法
5086
查看次数

如何从hibernate查询中获取java.util.Map?

我想知道从hibernate查询获取地图数组的最佳方法是什么.Google表示要迭代query.list(),并将对象创建/放入空地图数组中.
我想会有一些优雅而有效的方法来做到这一点.有人可以给我一些想法吗?

java hibernate

6
推荐指数
1
解决办法
4507
查看次数