如何使表user_roles将两列(userID,roleID)定义为复合主键.应该很容易,只是记不住/找不到.
在user实体中:
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "user_roles")
public List<RoleDAO> getRoles() {
return roles;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer getUserID() {
return userID;
}
Run Code Online (Sandbox Code Playgroud)
在roles实体中:
@ManyToMany(fetch = FetchType.LAZY)
@JoinTable(name = "user_roles")
public List<UserDAO> getUsers() {
return users;
}
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
public Integer getRoleID() {
return roleID;
}
Run Code Online (Sandbox Code Playgroud)
谢谢.
**更多信息
因此,有一个第三表user_roles即花费(由上述自动生成)userID从user实体和roleID从roles实体.现在我需要生成的table(user_roles)中的这两列是一个复合主键.
我有从种子创建的angular2项目,我在我的初始页面上添加了几个角度组件.其中一些加载图像 - 相对较慢,但实际问题是:
我恐怕即使在减少捆绑包大小之后,应用程序仍然会在没有任何请求的情况下自举1.5秒,然后再等待~1秒来加载组件的资源.我认为这将导致大约3秒多的加载时间.我的应用程序相对简单,我发现这是不可接受的.
问题1:有没有办法提前加载组件资源,只是在组件加载时引用它们?
Q2:有没有办法让应用程序自举更快?
我也接受其他建议:)
编辑:
我正在使用AoT编译,提供种子,我已采取措施降低app.js文件的大小.问题仍然存在于下载结束和第一个组件的资源调用之间的差距app.js.

我所做的(现在)只在服务器上:
这些服务器配置在NGINX和Apache上都是微不足道的,所以值得一试.
现在虽然网站加载速度快了很多,但这些更改并没有解决最初的问题(问题1和问题2).因此,如果您在我的位置,我正在寻找您可能也想要遵循的其他一些方法:
以下是一些帮助我提高初始负载的材料:
就我而言,Lazy Loading扮演着重要角色.
我Tomcat 7用来部署我的网络项目.在使用Eclipse interface启动和停止我的Tomcat 时我也更舒服,所以我已将其添加到Eclipse's Servers并检查了"Use Tomcat Installation" in Server Locations.我使用的另一件事是Tomcat's web Manager tool部署/取消部署项目.正如我们所知,为了使用Manager/html工具,您必须登录.用于身份验证的用户名和密码在tomcat-users.xml中设置,如下所示(在我的文件中):
<role rolename="tomcat"/>
<role rolename="manager"/>
<role rolename="manager-script"/>
<role rolename="manager-gui"/>
<role rolename="standard"/>
<role rolename="admin"/>
<user username="tomcat-eclipse" password="tomcat-eclipse" roles="tomcat,manager,manager-script,standard,admin"/>
<user username="root" password="toor" roles="manager-gui" />
Run Code Online (Sandbox Code Playgroud)
一切正常,直到某个时刻(我不确定,但可能在几次重启或重新部署后),我输入的配置被刷新,默认(空配置)文件覆盖我的自定义配置.
问:导致文件被覆盖的原因是什么?如何防止这种情况发生?谢谢.
编辑:
A:根据一些实验我的建议是:
your-tomcat-install-dir/webappsinto 的内容,your-eclipse-workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/以便拥有漂亮的Tomcat html界面(如教程:安装Tomcat 7并将其与Eclipse一起使用). 试试吧.:)
我对AngularJs很新.我正在制作一个Q&A应用程序,我必须以表格的形式提出一些问题和答案.我有三种类型的问题,我必须以不同的方式呈现.每个问题都有一个分配的类型.如果question.type是"MCQ",则选项或其答案应使用HTML复选框呈现,如果问题类型为NUM,则应使用单选按钮呈现其答案.我试过这个并使用AngularJs模板中的条件.我的代码是
<table>
<thead>
<td>Questions</td>
<td></td>
<td>Hints</td>
</thead>
<tr data-ng-repeat="question in quizdata.questions">
<td ng-if="question.type==MCQ">
<li>{[{question.question_text}]}</li>
<ol data-ng-repeat="answer in question.answers">
<li>
<input type="checkbox">{[{answer.answer_text}]}</input>
</li>
</ol>
</td>
<td ng-if="question.type==FIB">
<ol data-ng-repeat="answer in question.answers">
<li>
<input type="text"> </input>
</li>
</ol>
</td>
<td ng-if="question.type==NUM">
<ol data-ng-repeat="answer in question.answers">
<li>
<input type="radio">{[{answer.text}]}</input>
</li>
</ol>
</td>
<td></td>
<td ng-if="quizdata.attempt_hint">
{[{question.hint}]}
</td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
我试过这样的.但我认为如果条件没有执行.因为如果条件为false或true,它会渲染每种情况下的所有元素.我是否以正确的方式使用if条件?AngularJs模板中还有其他条件吗?帮助将受到高度赞赏.
javascript angularjs angularjs-directive angularjs-scope angularjs-ng-repeat
可能重复:
计算快速日志基数2上限
在C/C++中将特定整数从十进制转换为二进制时,找出特定整数有多少二进制数字的最快方法是什么?
防爆.47 (10) = 101111 (2)
因此47有六位数以二进制表示.
我想将一个object(ReportBean)持久化到数据库,但是我收到了错误消息:
javax.persistence.TransactionRequiredException: Transaction is required to perform this operation (either use a transaction or extended persistence context)
Run Code Online (Sandbox Code Playgroud)
这是一些代码:
实体
@Entity
@Table(name="t_report")
@Access(AccessType.FIELD)
public class ReportBean implements Serializable {
// fields (@Column, etc.)
// setters/getters methods
// toString , hashCode, equals methods
}
Run Code Online (Sandbox Code Playgroud)
允许EntityManager注入的自定义注释(带@Inject)
import javax.inject.Qualifier;
import static java.lang.annotation.ElementType.*;
import java.lang.annotation.Target;
@Qualifier
@Target({TYPE, METHOD, FIELD, PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
public @interface MyEm {
}
Run Code Online (Sandbox Code Playgroud)
EntityManager提供程序
import javax.enterprise.inject.Produces;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
public class EntityManagerProvider { …Run Code Online (Sandbox Code Playgroud) 我正在尝试实现一个多线程解决方案,以便我可以并行化我的业务逻辑,包括读取和写入数据库.
技术堆栈:Spring 4.0.2,Hibernate 4.3.8
以下是一些要讨论的代码:
@Configuration
public class PartitionersConfig {
@Bean
public ForkJoinPoolFactoryBean forkJoinPoolFactoryBean() {
final ForkJoinPoolFactoryBean poolFactory = new ForkJoinPoolFactoryBean();
return poolFactory;
}
}
Run Code Online (Sandbox Code Playgroud)
@Service
@Transactional
public class MyService {
@Autowired
private OtherService otherService;
@Autowired
private ForkJoinPool forkJoinPool;
@Autowired
private MyDao myDao;
public void performPartitionedActionOnIds() {
final ArrayList<UUID> ids = otherService.getIds();
MyIdPartitioner task = new MyIdsPartitioner(ids, myDao, 0, ids.size() - 1);
forkJoinPool.invoke(task);
}
}
Run Code Online (Sandbox Code Playgroud)
@Repository
@Transactional(propagation = Propagation.MANDATORY)
public class IdsDao {
public MyData getData(List<UUID> …Run Code Online (Sandbox Code Playgroud) 在下面的例子中(来自Vlad Mihalcea关于"使用JPA和Hibernate映射@OneToOne关系的最佳方法"的帖子):
@Entity(name = "PostDetails")
@Table(name = "post_details")
public class PostDetails {
@Id
private Long id;
@Column(name = "created_on")
private Date createdOn;
@Column(name = "created_by")
private String createdBy;
@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(foreignKey = @ForeignKey(name = "fk_post"))
@MapsId
private Post post;
public PostDetails() {}
public PostDetails(String createdBy) {
createdOn = new Date();
this.createdBy = createdBy;
}
//Getters and setters omitted for brevity
}
Run Code Online (Sandbox Code Playgroud)
我之间的单向关系PostDetails和Post实体,重新使用的ID Post作为ID PostDetails使用@MapsId.
除此之外我还补充说
@JoinColumn(foreignKey = @ForeignKey(name = …Run Code Online (Sandbox Code Playgroud) 以下数据库架构:
员工[EMP_ID(PK),姓名,薪水]
电话[ID(PK),number_str,OWNER_ID(FK)]
Employee_aud [EMP_ID(PK),REV(PK / FK),REVTYPE,姓名,薪水]
Phone_aud [ID(PK),REV(PK / FK),REVTYPE,number_str]
Employe_phone_aud [REV(PK / FK),OWNER_ID(PK / FK),REVTYPE(PK / FK)]
可以用以下Java实体表示:
员工人数:
@Entity
@Audited
public class Employee {
@Id
@GeneratedValue
@Column(name = "EMP_ID")
private long id;
@Column
private String name;
@Column
private int salary;
@OneToMany
@JoinColumn(name = "OWNER_ID", referencedColumnName = "EMP_ID")
private final List<Phone> phones = new ArrayList<Phone>();
public Employee(final String name, final int salary) {
this.name = name;
this.salary = salary;
}
public long getId() {
return id;
} …Run Code Online (Sandbox Code Playgroud) 上下文:
我从基于XML的Spring配置切换到了基于Java的配置.我的应用程序有一个基于JSP的Web层,Spring MVC,Spring Security和Hibernate作为持久性提供程序.
我设法在不同的配置类中分离整个XML配置:
WebConfig- 用于Spring MVC配置;
PersistenceConfig - 正如名称所述 - 用于JPA配置;
ServiceConfig - 仅适用于@Service和@Component注释类;
SecurityConfig - 用于Spring安全配置.
对于应用程序初始化,我有SecurityInitializer和WebAppInitializer类.
这是一些代码:
WebConfig
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.demo.app.web"})
public class WebConfig extends WebMvcConfigurerAdapter { /* Bean initialization */ }
Run Code Online (Sandbox Code Playgroud)
PersistenceConfig
@Configuration
@ComponentScan(basePackages = {"com.demo.app.dao"})
@EnableTransactionManagement(mode = AdviceMode.PROXY, proxyTargetClass = true)
public class PersistenceConfig { /* Bean initialization */ }
Run Code Online (Sandbox Code Playgroud)
ServiceConfig
@Configuration
@ComponentScan(basePackages = {"com.demo.app.service", "com.demo.app.component"})
public class ServiceConfig { /* Bean initialization */ }
Run Code Online (Sandbox Code Playgroud)
SecurityConfig
@Configuration …Run Code Online (Sandbox Code Playgroud) java ×4
hibernate ×2
spring ×2
algorithm ×1
angular ×1
angularjs ×1
annotations ×1
c ×1
c++ ×1
cdi ×1
eclipse ×1
foreign-keys ×1
java-ee ×1
javascript ×1
jpa-2.1 ×1
load ×1
many-to-many ×1
performance ×1
persistence ×1
primary-key ×1
servlet-3.0 ×1
tomcat7 ×1
transactions ×1