小编Max*_*Max的帖子

org.hibernate.LazyInitializationException - 无法初始化代理 - 没有会话

我得到以下异常:

Exception in thread "main" org.hibernate.LazyInitializationException: could not initialize proxy - no Session
    at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:167)
    at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:215)
    at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
    at sei.persistence.wf.entities.Element_$$_jvstc68_47.getNote(Element_$$_jvstc68_47.java)
    at JSON_to_XML.createBpmnRepresantation(JSON_to_XML.java:139)
    at JSON_to_XML.main(JSON_to_XML.java:84)
Run Code Online (Sandbox Code Playgroud)

当我尝试从main调用以下行时:

Model subProcessModel = getModelByModelGroup(1112);
System.out.println(subProcessModel.getElement().getNote());
Run Code Online (Sandbox Code Playgroud)

getModelByModelGroup(int modelgroupid)首先实现了这个方法,如下所示:

public static Model getModelByModelGroup(int modelGroupId, boolean openTransaction) {

    Session session = SessionFactoryHelper.getSessionFactory().getCurrentSession();     
    Transaction tx = null;

    if (openTransaction) {
        tx = session.getTransaction();
    }

    String responseMessage = "";

    try {
        if (openTransaction) {
            tx.begin();
        }
        Query query = session.createQuery("from Model where modelGroup.id = :modelGroupId");
        query.setParameter("modelGroupId", modelGroupId); …
Run Code Online (Sandbox Code Playgroud)

java orm session hibernate lazy-loading

159
推荐指数
10
解决办法
40万
查看次数

如何在Moment中枚举两个日期之间的日期

我有两个时刻:

var fromDate = moment(new Date('1/1/2014'));
var toDate   = moment(new Date('6/1/2014'));
Run Code Online (Sandbox Code Playgroud)

片刻是否提供了枚举这两个日期之间所有日期的方法?

如果没有,除了制作一个增加fromDate1 的循环直到它到达时,还有更好的解决方案toDate吗?

编辑:添加日期枚举方法和问题

我已经嘲笑了一个枚举两个日期之间日期的方法,但我遇到了一个问题.

  var enumerateDaysBetweenDates = function(startDate, endDate) {
    var dates = [];

    startDate = startDate.add(1, 'days');

    while(startDate.format('M/D/YYYY') !== endDate.format('M/D/YYYY')) {
      console.log(startDate.toDate());
      dates.push(startDate.toDate());
      startDate = startDate.add(1, 'days');
    }

    return dates;
  };
Run Code Online (Sandbox Code Playgroud)

我跑的时候看一下输出 enumerateDaysBetweenDates( moment(new Date('1/1/2014')), moment(new Date('1/5/2014'));

Thu Jan 02 2014 00:00:00 GMT-0800 (PST)
Fri Jan 03 2014 00:00:00 GMT-0800 (PST)
Sat Jan 04 2014 00:00:00 GMT-0800 (PST)
[ Sun Jan …
Run Code Online (Sandbox Code Playgroud)

javascript momentjs

42
推荐指数
5
解决办法
4万
查看次数

正则表达式允许1-3位数之间的数字值?

RewriteRule ^gallery/[0-9][0-9][0-9]/$ index.php?gallery_id=$1
Run Code Online (Sandbox Code Playgroud)

它允许任何长度为三位数的数字.我不知道如何允许少于三位数(或者超过三位数).

regex

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

AngularJS:ng-click无效

我是AngularJs的新手,ng-click没有按预期工作.我在互联网上搜索,按照教程,(这是有效的) - 但这不起作用!

我的代码:

<div class="row" ng:repeat="follower in myform.all_followers | partition:2">
    <ons-col class="views-row" size="50" ng-repeat="data in follower" >
        <img ng-src="http://dealsscanner.com/obaidtnc/plugmug/uploads/{{data.token}}/thumbnail/{{data.Path}}" alt="{{data.fname}}" ng-click="showDetail2(data.token)"/>
        <h3 class="title" ng-click="showDetail2('ss')">{{data.fname}}</h3>
    </ons-col>
</div>
Run Code Online (Sandbox Code Playgroud)

这是我的控制器

//Follows Controller
app.controller('FollowsController', function($scope, $http) {
    var ukey = window.localStorage.ukey;

    $scope.myform ={};
    $scope.myform.reports ="";
    $http.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
    var dataObject = "usertoken="+ukey;
    var responsePromise = $http.post(server_url+"follows/", dataObject,{});
    responsePromise.success(function(dataFromServer, status,    headers, config) {
        $scope.myform.all_followers = dataFromServer;
        console.log(dataFromServer);

        //alert(dataFromServer);
        $scope.showDetail = function(index) {
            profileusertoken =  index;
            $scope.ons.navigator.pushPage('profile.html'); 
        }

        function showDetail2(index) {
            alert("here");
        }

        $scope.showDetail2 = …
Run Code Online (Sandbox Code Playgroud)

javascript angularjs angularjs-ng-click

36
推荐指数
3
解决办法
13万
查看次数

文档元素的模拟对象

我有下一个测试代码:

it("Test", function() {
    loadResources();

    expect(document.getElementById('MyElement').innerHTML).toBe("my string");
});
Run Code Online (Sandbox Code Playgroud)

函数体loadResources():

document.getElementById('MyElement').innerHTML = "my string";
Run Code Online (Sandbox Code Playgroud)

我的测试失败并显示以下消息:

TypeError:无法设置null的属性"innerHTML".

看起来我需要为innerHTML创建模拟对象.我怎么能这样做?

javascript unit-testing jasmine

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

Java:从字符串中删除数值

我已经在这个社区的帮助下取代了从用户输入中删除数值,但是,我的代码只会在删除数字之前检索字母字符:

import java.util.Scanner;

public class Assignment2_A {

    public static void main(String[] args) {
        Scanner firstname = new Scanner(System.in);
        String firstname1 = firstname.next();
        firstname1 = firstname1.replaceAll("[^A-Z]","");
        System.out.println(firstname1);
    }
}
Run Code Online (Sandbox Code Playgroud)

例如,如果用户输入= S1234am,我只会回来:S.如何检索字符串中的剩余字符?

java string removeall

22
推荐指数
4
解决办法
8万
查看次数

如何使用spring DSL在camel中记录标头值

这似乎应该很简单,原谅双关语.我正试图在Spring DSL路线中记录骆驼的标题.我已经看到了Java DSL的答案,但我一直在寻找如何使它在Spring DSL中工作的徒劳.我试过了:

 <log message="ftping $simple{header.CamelFileName}"/>
Run Code Online (Sandbox Code Playgroud)

并且:

 <log message="ftping ${header.CamelFileName}"/>
Run Code Online (Sandbox Code Playgroud)

和其他几个排列/变体,但所有这些只是简单地记录该文本(即它们不替代实际的标题名称).

我错过了什么?


更新:这是我的xml文件的更大部分:

<split>
    <simple>${body}</simple>
    <setHeader headerName="CamelFileName">
        <simple>${body.batchNumber}.xml</simple>
    </setHeader>
    <log message="SLH - 5 -- marshalling an EFileBatch to XML" loggingLevel="DEBUG" />
    <marshal>
        <jaxb prettyPrint="true" contextPath="generated.gov.nmcourts.ecitation"
                partClass="generated.gov.nmcourts.ecitation.NMCitationEFileBatch"
                partNamespace="EFileBatch" />
    </marshal>

    <log message="SLH - 6 -- xslt transform to add schema location" loggingLevel="DEBUG" />
    <to uri="{{addSchemaLocationXsltUri}}"/>

    <log message="SLH - 7 -- ftp now initiating" loggingLevel="DEBUG" />
    <log message="ftping ${headers.CamelFileName}"/>

    <to uri="{{ftpOdysseyInputPath}}"/>
    <log message="SLH - 8 -- ftp now …
Run Code Online (Sandbox Code Playgroud)

java apache-camel

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

否则停止路线

嗨有这样的路线

<route id="route1">
<from uri="activemq:queuer1"/>
    <choice>
        <when>
            <simple>${header.urn} regex '^user*'</simple>
            <to uri="xslt:classpath:/xslt/rdf/user.xsl"/>
        </when>
        <when>
            <simple>${header.urn} regex '^userdata:.*'</simple>
            <to uri="xslt:classpath:/xslt/rdf/userdata.xsl"/>
        </when>
        ....
        <otherwise>
            <setHeader headerName="errorMsg ">
                <constant>no xsl file for this type</constant>
            </setHeader>
            <to uri="activemq:error"/>
        </otherwise> 
    </choice>
    <process ref="importer"/>
</route>
Run Code Online (Sandbox Code Playgroud)

现在,如果路由进入其他部分,则不应处理该消息.如果消息进入其他情况,我可以以某种方式停止路线吗?

可能性是我在所有部件中添加过程部件并在最后删除它.但是我们已经有几个部件和更多部件.

其他解决方案将是首选.

apache-camel

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

Serviceworker Bug event.respondWith

我serviceworker具有逻辑,当获取事件发生,首先它取其中包含一些布尔值(不是event.request.url)端点和检查值的基础上,我打电话值event.respondWith()为当前获取事件,我从缓存中提供响应.但是我收到以下错误,

未捕获(在promise中)DOMException:无法在'FetchEvent'上执行'respondWith':fetch事件已被响应

在这里检查m_state不等于Initial时抛出此错误

if (m_state != Initial) {
    exceptionState.throwDOMException(InvalidStateError, "The fetch event has already been responded to.");
    return;
}
Run Code Online (Sandbox Code Playgroud)

我怀疑,因为我有一个额外的获取事件,它以某种方式消耗了前一个fetch事件,它正在改变m_state变量,虽然我没有获取事件url.I我不知道是什么原因,什么是它的解决方案.但它为什么这么说

我正在粘贴下面的代码片段.

function fetchEvt(event) {        
    check().then(function (status) {
        if (status === 0) {
            handleRequest(event);
        }
    });
}

function checkHash() {
    return new Promise(function (resolve) {
        fetch(endpoint, { credentials: 'include' }).then(function (response) {
            return response.text();
        }).then(function (text) {
            resolve(text);
        });
    }
}

function handleRequest(event) {
    event.respondWith(caches.match(event.request.url).then(function (Response) {
        if (Response) {
            return …
Run Code Online (Sandbox Code Playgroud)

javascript service-worker progressive-web-apps

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

Secure.getString(mContext.getContentResolver(),"bluetooth_address")在Android O中返回null

当我试图通过这种方式在Android O设备上获取Blutooth地址时:

private String getBlutoothAddress(Context mContext){  
    // Check version API Android
    BluetoothAdapter myBluetoothAdapter;

    String macAddress;

    int currentApiVersion = android.os.Build.VERSION.SDK_INT;

    if (currentApiVersion >= android.os.Build.VERSION_CODES.M) {
        macAddress = Settings.Secure.getString(mContext.getContentResolver(), "bluetooth_address"); 
    } else {
        // Do this for phones running an SDK before lollipop
        macAddress = myBluetoothAdapter.getAddress();            
    }
}
Run Code Online (Sandbox Code Playgroud)

上面的所有代码仍然运行良好我仍然使用该代码Anroid O(8.0)它返回macAddress = null.

java android android-permissions android-bluetooth android-8.0-oreo

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