小编jef*_*eff的帖子

不推荐使用Java Date getDate(),重构为使用日历但看起来很难看

Eclipse警告我正在使用不推荐使用的方法:

eventDay = event.getEvent_s_date().getDate();
Run Code Online (Sandbox Code Playgroud)

所以我把它改写成了

eventDay = DateUtil.toCalendar(event.getEvent_s_date()).get(Calendar.DATE);
Run Code Online (Sandbox Code Playgroud)

它似乎工作,但它看起来很难看.我的问题是我是否以最好的方式重构了这个?如果没有,你会如何重构?我需要存储在bean中的日期的日期编号.

我最终在我的DateUtils中添加了一个方法来清理它

eventDay = DateUtil.getIntDate(event.getEvent_s_date());

public static int getIntDate(Date date) {
    return DateUtil.toCalendar(date).get(Calendar.DATE);
}
Run Code Online (Sandbox Code Playgroud)

java refactoring date

22
推荐指数
3
解决办法
5万
查看次数

JPA @ElementCollection列表指定连接列名称

我有以下实体:

@Entity
public class Shirt implements Serializable {

    @Id
    @Size(max=9)
    private String id;

    @ElementCollection
    @CollectionTable(name="SHIRT_COLORS")
    @Column(name="color")
    private List<String> colors = new ArrayList<String>();
    ...
Run Code Online (Sandbox Code Playgroud)

我将hibernate设置为autocreate时创建的集合表是

SHIRT_COLORS
 shirt_id
 color
Run Code Online (Sandbox Code Playgroud)

如何注释我的实体,以便连接列不是实体和pk的串联,以便创建的表是:

SHIRT_COLORS
 id
 color
Run Code Online (Sandbox Code Playgroud)

我试过@JoinColumn但是没用.实际上,生产中的SHIRT_COLORS表在应用程序之外进行管理,并且已经定义了列名.

java jpa

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

JPA实体映射,它基于另外两个实体映射关联

不确定这是否可行,但尝试WorkflowInstancePlayer player 根据两个其他实体映射WorkActionClass以及WorkflowInstance下面的实体映射哪些相关.

public class Action implements Serializable {
@Id
private Long action_id;

@ManyToOne
@JoinColumn(name = "work_action_class_id", referencedColumnName = "work_action_class_id")
private WorkActionClass workActionClass;

@ManyToOne
@JoinColumn(name = "workflow_instance_id", referencedColumnName = "workflow_instance_id")
private WorkflowInstance workflowInstance;

UPDATE: How can I map to a WorkflowInstancePlayer player?????
 @ManyToOne
 @JoinColumns( {
        @JoinColumn(name = "workflow_instance_id", referencedColumnName = "workflow_instance_id", insertable = false, updatable = false),
        @JoinColumn(name = "workActionClass.role_class_id", referencedColumnName = "role_class_id", insertable = false, updatable = false)
})
 private WorkflowInstancePlayer player;
Run Code Online (Sandbox Code Playgroud)


workflowInstancePlayer是基于workflow_instance_id …

java orm hibernate jpa hibernate-mapping

14
推荐指数
1
解决办法
1081
查看次数

提高第三方应用程序的可用性

我们使用是造成问题的一个伟大的交易,因为用户没有点击一个第三方应用Register点击之前,按钮Launch按钮,或者,如果他们点击Register第一个,这方面的细节页与RegisterLaunch按钮刷新并进入他们的投资组合.然后他们必须在他们的protfolio列表中重新找到该项目.

我认为第三方应用程序是.NET,并且正在使用knockout.js并且不允许嵌入到Frame中.

有哪些选项可以为用户提供指导,或者理想地使这个过程不那么痛苦?

我希望提供一个内部网页,只需按一下按钮即可发送这两个内容RequestLaunch动作.我发布了一个早期的问题Knockout数据绑定点击但无法得到一些工作.

在SO上似乎有一堆类似的问题,但我不确定这些问题/答案是否用于自动按钮点击自包含应用程序,因为我想从第三方应用程序外部进行操作(我是否可以访问他们的观点模型?).此应用程序可防止将其嵌入框架中.

这是第三方按钮代码

    <a class="btn btn-large btn-blue" href="javascript:void(0);" 
    data-bind="click: $root.clickAction.bind($data, ActionType)">
    <span data-bind="text: Title">Register</span></a>
Run Code Online (Sandbox Code Playgroud)

html javascript user-interface knockout.js zurb-joyride

12
推荐指数
1
解决办法
279
查看次数

JPA/Hibernate返回BigDecimal不长

我正在计算按月分组的SUM

Query q = entityManager.createNativeQuery(qlString);
q.setParameter("program", program);
@SuppressWarnings("unchecked")
List<Long> resultList = (List<Long>) q.getResultList();
long tend = System.currentTimeMillis();
Run Code Online (Sandbox Code Playgroud)

当我传入两个resultsLists(已关闭:Closed项目的结果列表,closedLate:结果列表项目已关闭)到计算百分比的方法时,我得到

 javax.servlet.ServletException: java.lang.ClassCastException: java.math.BigDecimal cannot be cast to java.lang.Long
Run Code Online (Sandbox Code Playgroud)

.

private List<Long> computeOTR(List<Long> closed, List<Long> closedLate) {
    List<Long> monthlyOTR = new ArrayList<Long>();
    long numerator;
    Long denominator;
    for (int i = 0; i <11; i++) {
        numerator = closed.get(i) - closedLate.get(i); <----java.lang.ClassCastException
        denominator = closed.get(i);
        long percentage = (int)(numerator * 100.0 / denominator + 0.5);
        monthlyOTR.add(i, percentage);
    }
    return monthlyOTR;
Run Code Online (Sandbox Code Playgroud)

}

在Eclipse中,调试模式关闭显示为BigDecimal.为什么这是我的decalre

List<Long> resultList …

java hibernate jpa

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

Maven无法在同一个仓库中转移许多工件中的一个

我正在尝试使用现有项目创建一个原型,mvn archetype:create-from-project但我得到了

Could not transfer artifact org.apache.maven.archetype:archetype-packaging:pom:3.0.0 
from/to central (https://repo.maven.apache.org/maven2):
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: 
unable to find valid certification path to requested target
Run Code Online (Sandbox Code Playgroud)

我在防火墙后面所以我按照这篇文章/sf/answers/1813908771/ 然后执行:

$ mvn archetype:create-from-project -Djavax.net.ssl.keyStore=trustCARoot.jks
 -Djavax.net.ssl.keyStorePassword=password  
 -Djavax.net.ssl.keyStoreType=JKS
 -Djavax.net.ssl.trustStore=trustCARoot.jks  
 -Djavax.net.ssl.trustStorePassword=password  
 -Djavax.net.ssl.trustStoreType=JKS
Run Code Online (Sandbox Code Playgroud)

我仍然得到相同的PKIX路径构建失败,但只是为了 archetype-packaging

[INFO] Setting default groupId: com.domain.rozycki
[INFO] Setting default artifactId: SkillsApp
[INFO] Setting default version: 0.0.1-SNAPSHOT
[INFO] Setting default package: com.domain.skillsapp
[INFO] Scanning for projects...
[INFO] Downloading: https://repo.maven.apache.org/maven2/org/apache/maven/archetype/archetype-packaging/3.0.0/archetype-packaging-3.0.0.pom
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Unresolveable …
Run Code Online (Sandbox Code Playgroud)

ssl certificate maven

8
推荐指数
1
解决办法
1076
查看次数

@PersistenceUnit注释不会创建EntityManageFactory emf = null

我尝试使用Sun Java PetStore演示.
在CatalogFacade类中,有以下注释:

@PersistenceUnit(unitName="myPetStorePU")
private EntityManagerFactory emf;
Run Code Online (Sandbox Code Playgroud)

在CatalogFacade Sun的所有方法中都有:

    EntityManager em = emf.createEntityManager();
Run Code Online (Sandbox Code Playgroud)

但是在尝试createEntityManager时,我得到emf的空指针异常.但是......如果我在该行上方添加以下行

    EntityManagerFactory emf = javax.persistence.Persistence.createEntityManagerFactory("myPetStorePU");
    EntityManager em = emf.createEntityManager();
Run Code Online (Sandbox Code Playgroud)

然后emf成功创建,持久性单元myPetStorePU也成功连接到数据库.所以它看起来像persistence.xml语法和它的位置是正确的.我想理解为什么注释不起作用,因为我认为只有使用注释而不是在每个方法中添加createEntityManagerFactory行是有原因的.

我的src/META-INF/persistence.xml文件如下所示:

<persistence-unit name="myPetStorePU">
    <description>Petstore Persistence Unit</description>
    <provider>oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider</provider>

  <class>com.sun.javaee.blueprints.petstore.model.Tag</class>
  <class>com.sun.javaee.blueprints.petstore.model.SellerContactInfo</class>
  <class>com.sun.javaee.blueprints.petstore.model.Product</class>
  <class>com.sun.javaee.blueprints.petstore.model.Item</class>
  <class>com.sun.javaee.blueprints.petstore.model.Category</class>
  <class>com.sun.javaee.blueprints.petstore.model.Address</class>
  <class>com.sun.javaee.blueprints.petstore.model.ZipLocation</class>
    <properties>
        <property name="toplink.jdbc.driver" value="oracle.jdbc.driver.OracleDriver"/>
        <property name="toplink.jdbc.url" value="jdbc:oracle:thin:@#############"/>
        <property name="toplink.jdbc.user" value="####"/>
        <property name="toplink.jdbc.password" value="#####"/>
        <property name="toplink.logging.level" value="INFO"/>
    </properties>

</persistence-unit>
Run Code Online (Sandbox Code Playgroud)

编辑:CatalogFacade位于petstore.model包中并实现ServletContextListener

<listener>
    <listener-class>com.sun.javaee.blueprints.petstore.model.CatalogFacade</listener-class>
</listener>
Run Code Online (Sandbox Code Playgroud)

在index.jsp中Sun有以下内容:

<%
CatalogFacade cf = (CatalogFacade)config.getServletContext().getAttribute("CatalogFacade");
List<Tag> tags=cf.getTagsInChunk(0, 12);
%>


public List<Tag> getTagsInChunk(int start, int chunkSize) {
//The next line …
Run Code Online (Sandbox Code Playgroud)

java persistence annotations jpa

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

如何将旧JSP的片段重构为某些JSF等价物?

ORIGINAL JSP(WorkItem.jsp)

<c:forEach var="actionItem" items="${workItem.work_action_list}">
    <c:if test="${actionItem.workActionClass.work_action_type_id == '1'}" >
       <%@ include file="inc_done_button.jsp" %>
    </c:if>
    <c:if test="${actionItem.workActionClass.work_action_type_id == '2'}" >
         <c:set var="actionItem" value="${actionItem}" scope="request" />
         <c:set var="checklist" value="${actionItem.meat}" scope="request" />
        <jsp:include page="inc_dynamic_checklist_v.jsp" flush="true" />
    </c:if>
    etc...
</c:forEach>
Run Code Online (Sandbox Code Playgroud)

原始Java

for (ListIterator<WorkflowInstanceWorkItemAction> actionIter = wfiwi.getWork_action_list().listIterator(); actionIter.hasNext();) {
    if ("2".equals(work_action_type_id)) {
        ChecklistInstanceForm ciForm = new ChecklistInstanceForm(this, authenticatedUser);
         ChecklistInstance ci = null; 
        ci = (ChecklistInstance) ciForm.getChkLstInstanceByWfiWiaOwner(wfiWorkItemAction, authenticatedUser);
    // Get the meat details for this action and inject it into the object
        wfiWorkItemAction.setMeat(ci);
    } …
Run Code Online (Sandbox Code Playgroud)

jsf jsp facelets composite-component

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

Oracle Unique Constraint基于列值

我有以下唯一约束

dup_Checklist_QNum UNIQUE (QUESTION_NO, IS_ACTIVE)
Run Code Online (Sandbox Code Playgroud)

我正在尝试阻止两个在激活时具有相同问题编号的问题(IS_ACTIVE值= 1).

在我不得不第二次提出问题之前,一切似乎都很好.

QUESTION_NO=1, TEXT="Have you..", REV=1, IS_ACTIVE=0  
QUESTION_NO=1, TEXT="Have you..", REV=2, IS_ACTIVE=0  <-- This should be ok but constraint was violated
QUESTION_NO=1, TEXT="Have you..", REV=3, IS_ACTIVE=1
QUESTION_NO=1, TEXT="Have you..", REV=3, IS_ACTIVE=1 <-- This should be throw constraint exception 
Run Code Online (Sandbox Code Playgroud)

我需要约束仅在IS_ACTIVE = 1时应用

sql oracle constraints

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

代码对于try块来说太大了

Eclipse编译并运行这个jsp很好但是当我部署到Sun One 6.1时,我得到"Code for too try for try {"

我正在尝试在执行聚合摘要时循环遍历bean列表.有关如何重构它以使其在我们过时的服务器上工作的任何建议吗? 截图

        <c:set var="ahJan" value="20" scope="request" />
        <c:set var="ahTot" value="246" scope="request" />

        <table border="0" width="95%" cellspacing="0" cellpadding="0" class="tableBlackBorder">
            <tr>
              <td>
              <table width="100%" border="0" cellpadding="1" class="tableInternalBorder" id="sortable">
                    <tr>
                       <td class="tl">Source</td>
                       <td class="tl">Program</td>
                       <td class="tl">Project</td>
                       <td class="tl">Contract</td>
                       <td class="tl">Line Code</td>
                       <td class="tl">Jan</td>
                       <td class="tl">Total</td>
                    </tr>

                          <c:set var="prevProgram" value="" scope="request" />
                          <c:set var="prevProject" value="" scope="request" />
                          <c:set var="prevContract" value="" scope="request" />
                          <c:set var="prevLinecode" value="" scope="request" />
                          <c:set var="prevBusArea" value="" scope="request" />
                          <c:set var="ctc_totSub" value="" scope="request" …
Run Code Online (Sandbox Code Playgroud)

java jsp web-applications

5
推荐指数
1
解决办法
8831
查看次数