如何处理Oracle将空字符串作为空存储在数据库中的情况?
我希望它存储为空字符串,因为它不是NULL,因为发出查询会更容易.
像这样的东西会选择空字符串和非空字符串,但不会选择空值
select * from mytable where myfield like '%';
Run Code Online (Sandbox Code Playgroud)
如果我想选择空值(原本应该是空字符串),我必须选择如下:
select * from mytable where myfield like '%' or myfield is null;
Run Code Online (Sandbox Code Playgroud)
我希望or myfield is null
稍后在我的sql语句中跳过这么做
我想到的当前解决方案是在应用程序级别处理这个问题,例如,在实体中,我将我的所有String字段默认值初始化为空格,例如:
@Entity
public class MyEntity {
private String name = " ";
public void setName(String name) {
if (isEmptyString(name)) {
name = " ";
}
}
...
}
Run Code Online (Sandbox Code Playgroud)
或许,我可以使用Oracle 11g中仍然不知道的新类型,它可以保留空字符串,而不会将其更改为空值?
谢谢 !
我试图"比较"2个集合之间的所有文档,这将仅返回true,如果只有2个集合中的所有文档完全相同.
我一直在搜索集合上的方法,但找不到可以做到这一点的方法.
我在mongo shell中尝试了类似这样的东西,但没有像我预期的那样工作:
db.test1 == db.test2
Run Code Online (Sandbox Code Playgroud)
要么
db.test1.to_json() == db.test2.to_json()
Run Code Online (Sandbox Code Playgroud)
无论如何,我还在java中使用spring-data mongodb.
请分享你的想法!谢谢.
我目前正在学习JSF 2.0,我很高兴这个会话范围功能的存在,这对于在同一页面上打开一个新选项卡或新窗口并拥有单独的资源非常有用,而不是相互覆盖.
但我很好奇如何以一种好的方式实现这一点,关于何时开始对话以及何时关闭它.
在我的例子中,我为每个JSF页面都有每个CDI bean.让我们说我有一个菜单,当它被点击时,这将导致页面A,并且从A,可能导致B,B可能导致C,C可能导致D,所有这4个页面都连接在一起链.
可以从B或C或D bean访问A的bean属性,也可以从C或D bean等访问B的属性.
现在我很困惑:
请分享您对此的看法.
即时通讯使用JPA2和Hibernate 3.6.x.
我在@Version上做了一个简单的测试.
假设我们有2个实体,
以下是场景:
每当对团队/玩家实体之一进行修改时,团队/玩家的版本将在刷新/提交时增加(修改后的记录上的版本增加).
使用持久性将新的玩家实体添加到团队的集合中,在持久化之后将为团队的版本分配实体(添加新实体,新实体将获得它的版本).
每当对其中一个玩家实体进行添加/修改/删除时,团队的版本将在刷新/提交时增加.(添加/修改/删除子记录,父版本也增加了)
我能理解数字1和2,但数字3,我不明白,为什么团队的版本增加了?
这让我想到了其他问题:
这是我的实验中的代码示例,证明当ReceivingGoodDetail是拥有方时,并且在刷新后版本在ReceivingGood中增加了.很抱歉,这使用其他实体,但ReceivingGood就像团队一样,ReceivingGoodDetail就像玩家一样.1 ReceivingGood/Team,很多ReceivingGoodDetail/Player.
/*
Hibernate: select receivingg0_.id as id9_14_, receivingg0_.creationDate as creation2_9_14_, .. too long
Hibernate: select product0_.id as id0_4_, product0_.creationDate as creation2_0_4_, .. too long
before persisting the new detail, version of header is : 14
persisting the detail 1c9f81e1-8a49-4189-83f5-4484508e71a7
printing the size of the header :
Hibernate: select details0_.receivinggood_id as receivi13_9_8_, details0_.id as id8_, details0_.id as id10_7_, .. too long …
Run Code Online (Sandbox Code Playgroud) 我想知道是否有可能在另一个Embeddable中有一个Embeddable的ElementCollection?
以下是我的供应商实体的示例,其中包含一个地址列表,该列表是可嵌入的类型:
@Entity
public class Supplier extends BaseCommonEntity {
@Column(unique=true)
private String supplierCode;
private String supplierName;
@ElementCollection
private List<Address> addresses;
....
Run Code Online (Sandbox Code Playgroud)
这是我的嵌入式地址,其中包含可嵌入电话的列表
@Embeddable
public class Address {
private String address;
private String city;
private String country;
private String postcode;
@ElementCollection
private List<Phone> phones;
public List<Phone> getPhones() {
return phones;
}
public void setPhones(List<Phone> phones) {
this.phones = phones;
}
...
Run Code Online (Sandbox Code Playgroud)
这是可嵌入的手机定义
@Embeddable
public class Phone {
private Long phoneCountryCode;
private Long phoneCityCode;
private Long phoneNo;
private Long faxCountryCode;
private Long …
Run Code Online (Sandbox Code Playgroud) 我想有一个可重复使用的ui组件,它与模型相关联.
例如 :
如果我只使用一个compositeComponent,我认为这个想法是有效的.
但是如果我使用多个相同类型的compositeComponent,这将不起作用,因为compositeComponent的JSF Bean将是相同的(在此示例中,我使用视图范围),并将共享一个或多个compositeComponents之间的状态.
这是一个粗略的例子,说明了我的困惑.在这种情况下,Page1.xhtml(使用Page1Bean.java的主模型)使用2个compositeComponents(由MyCompositeComponent.java的JSF Bean处理)
复合组件将类似于:
<!-- one composite component that has 2 chained selectOneMenus -->
<h:selectOneMenu
...
value="#{myCompositeComponentBean.firstComboValue}"
valueChangeListener="#{myCompositeComponentBean.yyy}">
<f:ajax event="valueChange" execute="@this" ... />
<f:selectItem itemLabel="Choose one .." noSelectionOption="true" />
<f:selectItems value="#{myCompositeComponentBean.firstComboList}" .... />
</h:selectOneMenu>
<h:selectOneMenu
...
value="#{myCompositeComponentBean.secondComboValue}"
valueChangeListener="#{myCompositeComponentBean.bbb}">
<f:selectItem itemLabel="Choose one .." noSelectionOption="true" />
<f:selectItems value="#{myCompositeComponentBean.secondComboList}" .... />
</h:selectOneMenu>
Run Code Online (Sandbox Code Playgroud)
复合组件的JSF Bean将如下:
// this model will serve the composite component
@Named
@Scope("view")
public class MyCompositeComponentBean {
private String …
Run Code Online (Sandbox Code Playgroud) 我正在尝试ajax功能,我很好奇我怎么能显示当我做ajax的东西时发生的错误消息?例如,我有一个primefaces按钮:
<p:commandButton value="Refresh" update="debugPanel messages"
action="#{checkbocLabBean.submit}"/>
Run Code Online (Sandbox Code Playgroud)
在测试该按钮时,似乎没有任何事情发生,直到我检查服务器日志,这是一个例外.事实证明我有一个错字.应该是#{checkboxLabBean.submit}.
我现在唯一能想到的就是禁用ajax,在我的情况下添加ajax ="false",错误就会显示出来.
在使用ajax请求时,是否还有其他方法可以在开发阶段将错误显示在浏览器中?
在JSF 2中使用带有BV的resourcebundle看起来像这样:
public class UserBean {
@Size(min=13, message="{creditcard.length}")
public String getCreditCard() {
return this.creditCard;
}
}
Run Code Online (Sandbox Code Playgroud)
我必须在其中一个属性文件中定义ResourceBundle条目,该文件可以在 faces-config.xml
creditcard.length =信用卡长度必须至少为13个字符
我们可以看到creditcard.length的值是非参数化的.
我可以进行参数化的ResourceBundle条目,可以从BV或其他地方填充吗?
这是我想要实现的简单方案:
creditcard.length =信用卡长度必须至少为{0}个字符.感谢您选择{1}信用卡.
而我希望这样的事情:
public class UserBean {
@Size(
min=13,
message="{creditcard.length}",
messageParams={"13", "plantvszombie"})
public String getCreditCard() {
return this.creditCard;
}
}
Run Code Online (Sandbox Code Playgroud)
当验证失败时,creditcard属性的错误消息将显示如下字符串:
信用卡长度必须至少为13个字符.感谢您选择plantvszombie信用卡.
这个ResourceBundle消息参数化是否可行?
请分享您对此事的经验.
谢谢 !
我目前正在尝试将记录的ID从一个页面发送到另一个页面.
所以在第1页中,我有这样的事情:
<p:column>
<h:link value="#{rpb.map['transNum']}" outcome="TInput.xhtml">
<f:param name="id" value="#{rpb.map['id']}" />
</h:link>
</p:column>
Run Code Online (Sandbox Code Playgroud)
在目标页面(TInput.xhtml)中,我有类似的东西来捕获id:
....
xmlns:fn="http://java.sun.com/jsp/jstl/functions">
<f:metadata>
<f:viewParam name="id" value="#{tInputBean.id}"></f:viewParam>
</f:metadata>
<h:head>
....
Run Code Online (Sandbox Code Playgroud)
现在,单击链接,转到第2页,第2页由一个视图范围的jsf bean处理.从我的调试来看,这是发生的顺序:
我想要实现的是: 在更新模型之后,我想对该记录id执行查询,获取它的bean以及它来自Business Service的详细信息列表.
我想知道我应该在哪里放置我的查询代码:
请赐教:)
Primefaces 2.2.1
Mojarra 2.1.2
我的jsf bean中有一个复杂的方法:
public void saySomething() {
log.debug("SAY SOMETHING !");
}
Run Code Online (Sandbox Code Playgroud)
还有jsf中的一个简单按钮:
<p:commandButton
value="say something"
process="@this" update="@none" action="#{timetableBean.saySomething}" />
Run Code Online (Sandbox Code Playgroud)
单击按钮,将导致我的简单日志记录:
DEBUG PhaseTracker - BEFORE PHASE INVOKE_APPLICATION 5
DEBUG TimetableBean - SAY SOMETHING !
DEBUG PhaseTracker - AFTER PHASE INVOKE_APPLICATION 5
Run Code Online (Sandbox Code Playgroud)
让我们进入下一个简单的案例.将相同的按钮放在ap:dataList中时,如下所示:
<p:dataList id="groupUsers2" value="#{timetableBean.group.users}" var="user" itemType="circle" style="padding:0; margin: 0;">
<p:commandButton
value="#{user.data['selected'] ? 'V' : 'X'}"
process="@this" update="@none" action="#{timetableBean.saySomething}" />
<p:commandLink value="#{user.userId} - #{user.name}" process="@this" />
</p:dataList>
Run Code Online (Sandbox Code Playgroud)
单击按钮,将导致我的简单日志记录:
DEBUG PhaseTracker - BEFORE PHASE INVOKE_APPLICATION 5
DEBUG PhaseTracker - …
Run Code Online (Sandbox Code Playgroud) jsf-2 ×6
jsf ×5
java ×4
hibernate ×3
jpa ×3
jpa-2.0 ×3
primefaces ×3
mongodb ×1
oracle ×1
spring-data ×1