小编Fir*_*ter的帖子

JPA坚持不写入数据库

我只是想了解JSF和JPA,但是每当我尝试将一个对象持久保存到数据库中时,它似乎都不会消失。这是我正在使用的代码:

@Named
@ManagedBean
@SessionScoped
public class BestemmingController implements Serializable{

@PersistenceUnit(unitName="RealDolmenTravelShopPU")
@PersistenceContext(unitName="RealDolmenTravelShopPU")

EntityManagerFactory emf = null;
public void submit(){


        try{
            emf = Persistence.createEntityManagerFactory("RealDolmenTravelShopPU");

            EntityManager em = emf.createEntityManager();

            //EntityTransaction et = em.getTransaction();
            //et.begin();

            Bestemming nieuweBestemming = new Bestemming();

            Land gezochtLand = em.find(Land.class, selectedLand);

            nieuweBestemming.setLand(gezochtLand);
            nieuweBestemming.setNaam(bestemmingNaam);

            em.persist(nieuweBestemming);

            //et.commit();
            //em.flush();
            em.close();
        }catch (Exception e){
            e.printStackTrace();
        }finally{
            emf.close();
        }
    }
Run Code Online (Sandbox Code Playgroud)

我尝试使用EntityTransaction,但它只是停止了我的应用程序,没有任何错误或任何其他信息。所以我省略了它,但仍然没有写掉。因此,我尝试了分别调用flush,但是那也没做。我真的很困惑为什么这不起作用。这可能是一些新手的错误,但是如果有人可以帮助我,我会喜欢的。

提前致谢!

java jpa eclipselink

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

读取文件时出现 UnauthorizedAccessException

我有和 ASP Web API,我试图从那里的调用返回一个文件。

在我的服务器上,我不断收到错误消息:

System.UnauthorizedAccessException:拒绝访问路径“E:\Data\Docs\specific\document.pdf”。在 System.IO.__Error.WinIOError(Int32 errorCode, String MaybeFullPath)
在 System.IO.FileStream.Init(String path, FileMode mode, FileAccess access, Int32 rights, Boolean useRights, FileShare share, Int32 bufferSize, FileOptions options, SECURITY_ATTRIBUTES secAttrs , String msgPath, Boolean bFromProxy, Boolean useLongPath, Boolean checkHost)
在 System.IO.FileStream..ctor(String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, FileOptions options, String msgPath, Boolean bFromProxy) at System.IO.FileStream..ctor(String path, FileMode mode)在 GIS.Backend.Assets.BLL.Document.GetByUrl(String url) 在 GIS.Backend.Assets.WebApi.Controllers.DocumentController.Get(String url)

我猜这是出错的地方:

string documentenPath = System.Web.Configuration.WebConfigurationManager.AppSettings["DocumentenDir"].ToString();
        string fullUrl = documentenPath + url;

        Stream file = new …
Run Code Online (Sandbox Code Playgroud)

c# asp.net io file asp.net-web-api

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

标签 统计

asp.net ×1

asp.net-web-api ×1

c# ×1

eclipselink ×1

file ×1

io ×1

java ×1

jpa ×1