JPA(hibernate)不会在persist上插入,需要刷新(JPA (hibernate) does not insert on persist, needs to be flushed)
我有一个无状态bean来观察事件并保存记录:
@Stateless public class Manager { @Inject Repository repository; Manager() {} @Inject Manager(Repository repository) { this.repository = repository; } public void EventHandler(@Observes MyEvent myEvent) { save(event.obj); } private save(Object object) { repository.add(object); } }
我的存储库是这样的:
@Stateless public class Repository { @PersistenceContext EntityManager em; Repository() {} public void add(Object object) { em.persist(object); // em.flush(); <--- } }
除非我取消注释,否则它不起作用我不明白的是为什么我需要冲洗! 交易不应该自动提交吗?
可能是因为我有一个EJB容器并且Observe启动的cdi事务从未实际结束但是做了一些奇怪的事情? 或者它结束但不提交因为他不了解EJB?
I have a stateless bean that observes an event and saves a record:
@Stateless public class Manager { @Inject Repository repository; Manager() {} @Inject Manager(Repository repository) { this.repository = repository; } public void EventHandler(@Observes MyEvent myEvent) { save(event.obj); } private save(Object object) { repository.add(object); } }
My repository is like this:
@Stateless public class Repository { @PersistenceContext EntityManager em; Repository() {} public void add(Object object) { em.persist(object); // em.flush(); <--- } }
It doesn’t work unless I uncomment the line The thing I don’t understand is why do I need to flush! Shouldn’t the transaction commit automatically?
Could it be that I have an EJB container and the cdi transaction started by Observes never actually ends but do something weird? Or it ends but doesn’t commit because he doesn’t know about EJB?
原文:https://stackoverflow.com/questions/30551473
最满意答案
我会将导航栏的高度作为变量,这样无论使用什么设备都没关系。
$('a[href^="#"]').on('click', function(event) { var target = $( $(this).attr('href') ), navBarHeight = $(".nav").height(); if( target.length ) { event.preventDefault(); $('html, body').animate({ scrollTop: (target.offset().top) - navBarHeight }, 1000); } });
显然,更改
$(".nav")
以使用正确的选择器。 您还可以通过向navBarHeight
添加常量来添加偏移量。I would get the height of the nav-bar as a variable, that way it doesn't matter what device is used.
$('a[href^="#"]').on('click', function(event) { var target = $( $(this).attr('href') ), navBarHeight = $(".nav").height(); if( target.length ) { event.preventDefault(); $('html, body').animate({ scrollTop: (target.offset().top) - navBarHeight }, 1000); } });
Obviously, change
$(".nav")
to use the correct selector for your purpose. You could also add an offset by adding a constant tonavBarHeight
.
相关问答
更多-
您是否签出以下代码: https : //github.com/serbanghita/Mobile-Detect Did you checkout following code: https://github.com/serbanghita/Mobile-Detect
-
IMO这些是最好的断点: @media (min-width:320px) { /* smartphones, portrait iPhone, portrait 480x320 phones (Android) */ } @media (min-width:480px) { /* smartphones, Android phones, landscape iPhone */ } @media (min-width:600px) { /* portrait tablets, portrait iPa ...
-
使用Modernizr来测试平板电脑和手机 - 想要的意见(Using Modernizr to test for tablet and mobile - Opinions wanted)[2023-10-17]
Modernizr可以检查触摸事件 为了测试设备是平板电脑还是手机或桌面设备,我可能会更倾向于使用用户代理。 看看DetectMobileBrowsers.com上的脚本 Modernizr只是测试浏览器是否支持某些功能。 据我所知,它似乎没有测试browser_type == mobile和东西沿着这些行... 请记住,现在很多台式电脑现在都有触摸屏幕,所以即使检测到触摸支持也不能保证是移动设备或平板电脑。 Modernizr can check for touch events For testing ... -
您可以为该特定页面创建一个具有相同名称的新布局 res/layout/main_activity.xml # For handsets (smaller than 600dp available width) res/layout-sw600dp/main_activity.xml # For 7” tablets (600dp wide and bigger) res/layout-sw720dp/main_activity.xml # For 10” tablets (720 ...
-
在你的custom.css中: /* Handhelds */ @media (max-device-width: 480px) { .nomobilebanner { display: none !important; } ... } 和 /* iPad Portrait */ @media screen and (min-device-width: 481px) and (max-device-width: 1024px) and (orientation:po ...
-
我会将导航栏的高度作为变量,这样无论使用什么设备都没关系。 $('a[href^="#"]').on('click', function(event) { var target = $( $(this).attr('href') ), navBarHeight = $(".nav").height(); if( target.length ) { event.preventDefault(); $('h ...
-
响应式图像[ https://github.com/filamentgroup/Responsive-Images ]看起来可能非常接近您正在寻找的内容。 它不一定是jQuery / mobile特定的,但它会根据屏幕分辨率加载不同的大小。 Responsive images [https://github.com/filamentgroup/Responsive-Images] looks like it might be pretty close to what you're looking for. ...
-
不错的网站。 :D让我们试着解决你的问题。 确保在任何媒体查询中都没有该CSS代码,因为它可能会阻止该内容。 您可能还尝试使用与移动设备相同的CSS添加新的媒体查询,例如@media (min-width: 481px) { } 。 在再次加载站点之前清理移动浏览器的缓存。 mobileand tablet browsersdo not support background-attachment: fixed. changing this, solved the problem
-
这是使用simple flag另一种解决方案: 在特定值文件中设置一个布尔值,如say( res/values-xlarge/ ):
true false -
从手机到平板电脑时如何增加字体大小[关闭](How to increase font size when going from mobile to tablet [closed])[2022-05-28]
实际上,我们鼓励您更好地利用平板电脑中的更多空间,例如对不同的屏幕尺寸使用不同的片段布局。 但是, 如果你只想为平板电脑做大事,你可以在android中使用资源限定符 。 在您的情况下,在res文件夹中创建另一个值目录,例如,对于宽度最小的600dp平板电脑的值-sw600dp,然后将dimens.xml放在该文件夹中。 在res / values-sw600dp / dimens.xml里面