小编Hou*_*dri的帖子

JPA 延迟加载在 Spring Boot 中不起作用

我在谷歌上搜索了很多,Spring Boot(最新版本)可能没有延迟加载不起作用,这真的很奇怪。以下是我的代码片段:

我的资源:

 public ResponseEntity<Page<AirWaybill>> searchAirWaybill(CriteraDto criteriaDto, @PageableDefault(size = 10) Pageable pageable{
airWaybillService.searchAirWaybill(criteriaDto, pageable);
        return ResponseEntity.ok().body(result);
}
Run Code Online (Sandbox Code Playgroud)

我的服务:

@Service
@Transactional
public class AirWaybillService {

//Methods

 public Page<AirWaybill> searchAirWaybill(AirWaybillCriteriaDto searchCriteria, Pageable pageable){
    //Construct the specification
            return airWaybillRepository.findAll(spec, pageable);
   }
}
Run Code Online (Sandbox Code Playgroud)

我的实体:

@Entity
@Table(name = "TRACKING_AIR_WAYBILL")
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class, property="@airWaybillId") //to fix Infinite recursion with LoadedAirWaybill class
public class AirWaybill{
//Some attributes
    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "FK_TRACKING_CORPORATE_BRANCH_ID")
    private CorporateBranch corporateBranch;
}
Run Code Online (Sandbox Code Playgroud)

并且在调试时,我仍然会加载所有延迟加载的属性。见下图。

在此处输入图片说明

我的问题之一是杰克逊会参与这种行为吗?有什么方法我可能错过了激活延迟加载?

编辑

另一个问题,调试器是否会参与破坏延迟加载?

编辑2:

对于规范构建,我有:

public static Specification<AirWaybill> …
Run Code Online (Sandbox Code Playgroud)

java spring hibernate spring-data-jpa spring-boot

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

DocumentViewer无法使用Ionic 3

我试着在这里使用ionic/cordova插件.

所以我把这段代码放在我的页面中:

  showDocument() {
    var options: DocumentViewerOptions = {
      title: 'A book',
      documentView: { closeLabel: '' },
      navigationView: { closeLabel: '' },
      email: { enabled: true },
      print: { enabled: true },
      openWith: { enabled: true },
      bookmarks: { enabled: true },
      search: { enabled: false },
      autoClose: { onPause: false }
    }
    this.docViewer.viewDocument('assets/arabic.pdf', 'application/pdf', options);
  }
Run Code Online (Sandbox Code Playgroud)

还有一个简单的按钮可以在html页面中启动它:

<ion-content>
  <button  ion-button round (click)="showDocument()">
    Read
  </button>
</ion-content>
Run Code Online (Sandbox Code Playgroud)

但我在模拟器中看不到任何内容(因为无法在浏览器上运行它)

离子信息在那里:

在此输入图像描述

更新:

这是我使用我的设备和chrome devtools进行调试时得到的结果:

在此输入图像描述

更新2:

我试图使用绝对路径,但我有空值,我做了这些更改:

import …
Run Code Online (Sandbox Code Playgroud)

javascript android cordova ionic-framework

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

交易未激活 - Hibernate - JPA

我有这个类专门用于通过hibernate的persistance层在db中保存数据.

public class TLinkEquipementDAOImpl implements TLinkEquipementDAO {

    private static final Log log = LogFactory
            .getLog(TLinkEquipementDAOImpl.class);

    @PersistenceContext
    private EntityManagerFactory emf = PersistenceManager.getInstance()
            .getEntityManagerFactory();
    private EntityManager entityManager = emf.createEntityManager();

    private EntityTransaction tx = entityManager.getTransaction();

    public void persist(TLinkEquipement transientInstance) {
        log.debug("persisting TLinkEquipement instance");
        try {
            tx.begin();
            entityManager.persist(transientInstance);
            tx.commit();
            log.debug("persist successful");
        } catch (RuntimeException re) {
            tx.rollback();
            log.error("persist failed", re);
            throw re;
        }
    }
//Staff
}
Run Code Online (Sandbox Code Playgroud)

问题是它不会持久存储数据.

堆栈是:

Exception in thread "main" java.lang.IllegalStateException: Transaction not active
    at org.hibernate.ejb.TransactionImpl.rollback(TransactionImpl.java:82)
    at sau.se.domain.dao.Impl.TLinkEquipementDAOImpl.persist(TLinkEquipementDAOImpl.java:47)
    at sau.se.domain.service.Impl.TLinkEquipementServiceImpl.persist(TLinkEquipementServiceImpl.java:29)
    at sau.se.extractor.InfoExtract.getAllSPData(InfoExtract.java:346) …
Run Code Online (Sandbox Code Playgroud)

java hibernate jpa

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

用c ++实现机器人技术的实时编程

我正在使用C++和OpenCV开展机器人项目.在这一步中,我遇到了一个问题,包括:

我有两个方法moveRight()moveLeft()我在我的代码依次调用,但问题是,第二个不运行,因为第一个需要时间(机器人运动的时间),但是当我把Sleep(5000)他们之间的(我猜那五一秒钟足够运动),一切都好.

什么是避免使用的编程解决方案Sleep(因为它会产生一些其他问题)?

c++ robot real-time

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

如何开始学习Android内核开发

我将开始在Android系统内核开发下工作,我没有想法。我所知道的是,我必须具备 Linux、c 和 C++ 方面的知识,而且我拥有所有这些知识,但我应该开始一些培训,所以我需要一些第一步。任何帮助,将不胜感激。谢谢大家

android linux-kernel embedded-linux

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

在 Moment 阿拉伯语本地化中自定义数值

我想在 moment.js 中创建我自己的语言环境,它的父级应该是阿拉伯语本地环境,但我只想更改为显示的数字格式0-9,而不是默认显示。

根据文档,我可以从以下开始:

moment.defineLocale('ar-sa-mine', {
  parentLocale: 'ar-sa',
  /*
     here I need to specify the numeric: change **this ?? to 29**
  */
});
Run Code Online (Sandbox Code Playgroud)

localization momentjs

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

休眠中的驱逐和分离有什么区别?

evict我在理解和之间的区别时遇到了一些困难detachevict无论如何都会分离会话,如果是的话,有什么区别?我读到它从二级缓存中删除了对象,但没有得到它。

java hibernate

5
推荐指数
2
解决办法
1883
查看次数

HashMap null值问题

两个结果之间有什么区别.

  1. 当我用键空值时

  2. 当密钥本身不存在时

在上面两个条件结果都是null.那么如何识别我的关键价值呢?

Map map = new HashMap();
map.put(1,null);
System.out.println(map.get(1));
System.out.println(map.get(2));
Run Code Online (Sandbox Code Playgroud)

回答:

null

null
Run Code Online (Sandbox Code Playgroud)

java

4
推荐指数
1
解决办法
161
查看次数

@RestControllerAdvice和@ControllerAdvice一起

我有一个带有@Controllers和@RestControllers 的Spring MVC应用程序。我当时在想:当我遇到异常时@Controller,它将由我处理;@ControllerAdvice当我遇到异常时@RestController,将由我处理@RestControllerAdvice...但是现在,我认为这不是事情的工作方式,因为我@ControllerAdvice正在捕获所有内容,甚至是由@RestController... 引发的任何异常,我不知道是否应该发生这种情况。这是我的代码:

 @ControllerAdvice
 public class ExceptionHandlerController {

 private final String DEFAULT_ERROR_VIEW = "error/default";

  @ExceptionHandler(Exception.class)
  public ModelAndView defaultErrorHandler(HttpServletRequest req, Exception e) 
  {   
      ModelAndView mav = new ModelAndView();
      mav.addObject("exception", e);
      mav.addObject("danger", e.getMessage());
      mav.addObject("url", req.getRequestURL());
      mav.setViewName(DEFAULT_ERROR_VIEW);
      return mav;
  }
}


@RestControllerAdvice
public class ExceptionHandlerRestController {

  @ExceptionHandler(Exception.class)
  public ResponseEntity<String> defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
      return new ResponseEntity<>(" test "+e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR);        
  }    
}
Run Code Online (Sandbox Code Playgroud)

spring controller exception-handling spring-restcontroller

4
推荐指数
1
解决办法
7785
查看次数

IE8中不支持JQuery

一直有问题IE.

在我的网页中,我在本地JQuery包括:

<script type="text/javascript" src="../jsp/jquery-2.0.2.min.js"></script>
<script type="text/javascript" src="../jsp/jquery-ui-1.10.3.custom.js"></script>
<script type="text/javascript" src="../jsp/init.js"></script>
<script type="text/javascript" src="../jsp/tajweed.js"></script>
<script type="text/javascript" src="../jsp/tajweed-tools.js"></script>  
Run Code Online (Sandbox Code Playgroud)

但是,它给出了这些错误:

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; InfoPath.3)
Timestamp: Thu, 25 Jul 2013 10:17:38 UTC


Message: 'JSON' is undefined
Line: 4
Char: 562
Code: 0
URI: http://localhost/play/jsp/jquery-2.0.2.min.js


Message: 'jQuery' is undefined
Line: 6
Char: 1
Code: 0
URI: …
Run Code Online (Sandbox Code Playgroud)

jquery internet-explorer cross-browser

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

在Java中将斜杠添加到枚举中

我需要创建一个enumeration这样的:

public enum STYLE {
ELEMENT1(0), A/R (2)
//Staff
};
Run Code Online (Sandbox Code Playgroud)

Java不允许这样做.有什么解决方案吗?谢谢

java enums enumeration slash

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

比较C++的最小用户输入

我试图在3个输入中找到最小的数字.这是我的代码:

int main ()
{
     double x = 4.0;
     double y = 5.0;
     double z = 3.0;
     smallest(x,y,z);
     cout << smallest << endl;
     system("PAUSE");

}

double smallest(double x, double y, double z)
{
     double smallest;

     if ((x < y)||(x< z)) {
        smallest = x;
     } else if ((y < z)||(y < x)) {
        smallest = y;
     } else {
        smallest = z;
     }
     return smallest;

}
Run Code Online (Sandbox Code Playgroud)

但是,我一直在收到错误.它声明了我在main方法中使用未声明标识符的最小方法.这在使用eclipse但不是visual studio时有效.有人可以向我解释原因吗?

提前致谢.

更新部分.

所以我试着对这个程序进行验证.我想确保用户只输入号码,这里是我的代码:

    double x, y, z;
bool correct_input = false;
do{ …
Run Code Online (Sandbox Code Playgroud)

c++ if-statement

0
推荐指数
2
解决办法
315
查看次数